0

我有以下重写规则,但每次我重新启动 Apache 时,它​​们都会阻止 apache 重新启动和失败。

一个错误是...

Starting httpd: Syntax error on line 82 of /var/www/vhosts/current_release/url-rewrite-maps/catchall.txt: RewriteRule: cannot compile regular expression '^/ProductDetails\.aspx\?PromotionID\(.*)\&id\(.*)$' [FAILED]

RewriteRule ^/ProductSearch\.aspx\?Ntt\=(.*)\&N\=(.*)$ catalogsearch/result/?q=$2 [R=302,L,NC]  
#old search redirect to search

RewriteRule ^/ProductSearch\.aspx\?viewall\=1\&N\=(.*)$ productsearch.aspx?N=$1 [R=302,NC]  
#viewall with N parameter to another redirect rule for URL with N= value only

RewriteRule ^/ProductSearch\.aspx\?(Ne|No)\=(.*)\&N\=(.*)$ productsearch.aspx?N=$3 [R=302,NC]  
#url with Ne OR No param and N= to productsearch.aspx redirect on URLs with N= only

RewriteRule ^/ProductDetails\.aspx\?PromotionID\=(.*)\&id\=(.*)$ productdetails.aspx?id=$2 [R=302,NC]  
#should pass the PID into the ID= and redirect from there

RewriteRule ^/ProductDetails\.aspx\?id\=(.*)\&RSSLINK\=(.*) productdetails.aspx?id=$1 [R=302, NC]

谢谢,

布拉德

4

1 回答 1

1

这是因为您尝试做的事情是无效的。您不能通过正则表达式匹配模式访问查询字符串——它是不允许的。您必须使用重写条件来获取查询字符串,例如:

RewriteCond %{QUERY_STRING}          PromotionID=(.*?)&id=(.*) [NC]
RewriteRule ^/ProductDetails\.aspx$  productdetails.aspx?id=%2 [R=302,NC,L]

您可以创建一个梯子,并在底部放置一个包罗万象

RewriteCond %{ENV:REDIRECT_STATUS}   ^$
RewriteRule ^                        /catchall.txt [L]

这将对任何与之前的规则不匹配的请求进行内部重定向到您的全部捕获。条件是停止无限重定向循环。

于 2013-01-16T02:15:06.513 回答