mod_rewrite RewriteRule异常

时间:2014-09-04 14:52:50

标签: regex apache .htaccess mod-rewrite url-rewriting

我正在为我的网站准备重写规则。当目标网址包含“%3A”等字符时,我遇到了问题。 Apache mod_rewrite只在重写url时删除“%3”。

例如我需要重写网址

/primed-white-mdf-skirting+architrave/  

/Products/Decorating+Interiors/Mouldings/Skirting/c/1000589?q=%3AtopSellers%3AColour%3AWhite&text=#

我为此制定了规则。这是:

RewriteRule ^primed-white-mdf-skirting\+architrave/ /Products/Decorating+Interiors/Mouldings/Skirting/c/1000589?q=%3AtopSellers%3AColour%3AWhite&text=# [R=301,L,NE]

所以重写传递给:

 /Products/Decorating+Interiors/Mouldings/Skirting/c/1000589?q=AtopSellersAColourAWhite&text=%23

为什么会这样?请帮忙

1 个答案:

答案 0 :(得分:1)

您需要转发%,否则%3被视为back-reference中被捕获群组的RewriteCond

RewriteRule ^primed-white-mdf-skirting\+architrave/ /Products/Decorating+Interiors/Mouldings/Skirting/c/1000589?q=\%3AtopSellers\%3AColour\%3AWhite&text=# [R=301,L,NE,QSA,NC]