我试图做一些相对简单的.htaccess规则来重定向某些网址。规则不匹配。这就是我所拥有的:
RewriteEngine On
RewriteBase /
# This works fine
RewriteCond %{QUERY_STRING} ^id=2$ [NC]
RewriteRule ^products\.php$ /? [R=301,NE,NC,L]
# This doesn't match at all
RewriteRule ^products/-Smart-Smoker-\'Storm\'-White-Manual-Electronic-Cigarette-\(510\)\.html http://www.smartsmoker.co.uk/products/-Smart-Smoker-Storm-White-Manual-Electronic-Cigarette-%28510%29.html [NC,R=301]
# Neither does this
RewriteRule ^products/Christmas-Cracker-%252d-FREE-Shipping\.html$ http://www.smartsmoker.co.uk/categories/Electronic-Cigarette-Kits/Breeze-Mini-Electronic-Cigarette/ [L,R=301]
答案 0 :(得分:0)
有重写戏剧的最佳选择是将其分解为最短的功能匹配,然后对其进行扩展,注意上述条件可能会影响您想要实际测试的内容。话虽如此,我自己使用下面的最小例子看不出任何问题:
RewriteEngine on
RewriteBase /
RewriteRule ^products/-Smart-Smoker-\'Storm\'-White-Manual-Electronic-Cigarette-\(510\)\.html$ /test.html [L]
您重定向到的网址也不必进行网址编码。