apache重启后mod_rewrite规则失败

时间:2013-01-15 18:20:40

标签: apache magento mod-rewrite redirect seo

我有以下重写规则,但每次重启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]

谢谢,

布拉德

1 个答案:

答案 0 :(得分: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]

这将执行任何与先前规则不匹配的请求的内部重定向到您的catch。条件是停止无限重定向循环。