2014-04-10 203 views
1

,所以我一直在負責,使這個URL工作的.htaccess重寫規則匹配問題

foobar.com/city.homes 

這..

foobar.com/page-2/city.homes 

這種重寫

RewriteRule ^(.*).homes$  search-results.asp?area=$1&proptype=home 

所以我第一次嘗試似乎,邏輯上,我認爲

RewriteRule ^page-(.*)/(.*).homes$  search-results.asp?area=$2&proptype=home&page=$1 

然而,無論我把它放在.htaccess中,它的工作方式並不像我期待的那樣。它永遠不符合第二條規則,除非我刪除第一條。

回答

1

你的正則表達式是錯誤的,並且是重疊的。

讓你的規則是這樣的:

RewriteRule ^page-([0-9])/([^.]+)\.homes$ search-results.asp?area=$2&proptype=home&page=$1 [L,QSA] 

RewriteRule ^([^.]+)\.homes$ search-results.asp?area=$2&proptype=home [L,QSA] 
+0

的偉大工程! thxs! – menriquez

+1

不客氣,很高興它解決了。 – anubhava

+0

所以我想這是如何工作的是,它從eol向後搜索並做匹配的方式?我真的想知道這裏的技巧,因爲我花了一個小時試圖讓事情工作:) – menriquez