2013-01-15 28 views
0

我有以下重寫規則,但每次重新啓動Apache時,都會阻止Apache重新啓動並失敗。Apache重新啓動後mod_rewrite規則失敗

一個錯誤是...

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

這是因爲你正在嘗試做的是無效的。您不能通過正則表達式匹配模式訪問查詢字符串 - 不允許。你必須使用一個重寫條件拿起查詢字符串,例如:

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] 

這將做一個內部將以前規則未匹配的任何請求重定向到您的全部。條件是停止無限重定向循環。

+0

我有一系列指向不同重寫映射文件的指針,每個指針都有一個條件和兩條規則,並且在這些特定示例的結尾處包含一個catchall.txt。那麼,你可以在這樣的包含文件中使用RewriteCond嗎? (無論如何要嘗試......) – Brad

+0

查看編輯我的答案:-) – TerryE

+0

我最終不得不將重寫條件放在apache .conf中,而不是放在我單獨的catchall文件中。在你描述的所有陳述之後,我最終沒有使用這個傳奇,它給我帶來了其他問題。 – Brad