Apache mod_rewrite.htaccess规则与转义字符不匹配



我正在尝试做一些相对简单的.htaccess规则来301重定向一些URL。规则不匹配。这是我所拥有的:

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]

重写戏剧时的最佳选择是将其分解为功能最短的匹配,然后对其进行扩展,注意以上条件可能会影响您想要实际测试的内容。话虽如此,我自己使用下面的最小示例看不到任何问题:

RewriteEngine on
RewriteBase /
RewriteRule ^products/-Smart-Smoker-'Storm'-White-Manual-Electronic-Cigarette-(510).html$ /test.html [L]

此外,重定向到的URL不必进行URL编码。

最新更新