301重定向不使用“+”符号

时间:2013-10-22 13:37:30

标签: regex apache .htaccess mod-rewrite redirect

我想301重定向以下网址

  

www.domain.com/Gallery2/v/South/Actress/Ritu+Kaur+Actress+Photos

  

www.domain.com/gallery/ritu-kaur.html

我尝试了以下内容,但没有奏效,

RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^Gallery2\/v\/South\/Actress\/Ritu\+Kaur\+Actress\+Photos\/$ "http\:\/\/www\.indiancinemagallery\.com\/gallery\/ritu\-kaur\.html" [R=301,L]

请告知

2 个答案:

答案 0 :(得分:0)

+符号可能会被规范化为空格,请尝试用空格替换它们:

RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^Gallery2/v/South/Actress/Ritu\ Kaur\ Actress\ Photos/$ http://www.indiancinemagallery.com/gallery/ritu-kaur.html [L,R=301]

URI在对RewriteRule中的正则表达式进行匹配之前会被解码,因此,除非您的网址已经编码+个符号,否则它们会被解码为空格而不是

答案 1 :(得分:0)

在任何其他重写规则之前将此规则放在Gallery2/.htaccess

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^v/South/Actress/Ritu\+Kaur\+Actress\+Photos/?$ http://www.indiancinemagallery.com/gallery/ritu-kaur.html [R=301,L,NC]