2015-09-02 52 views
0

我希望有人能幫助我,重定向動態地址htaccess的

我有一組頁面,看起來像這樣:

www.example.com/country/city/county/business-name/listing-id/contact.htm 

和另一組的頁面,看起來像這樣:

www.example.com/country/city/county/business-name/listing-id/index.htm 

唯一不同的是我的動態網址結尾處的聯繫人和索引詞。

當然每個頁面都不一樣,其他城市,國家等等。

我要的是重定向所有

www.example.com/country/city/county/business-name/listing-id/contact.htm 

www.example.com/country/city/county/business-name/listing-id/index.htm 

動態。

這是我今天的代碼,但它不工作:

RewriteRule ^(.*).ht$ city.php?c=$1 

RewriteRule ^(.*)/(.*)/index.html$ bizlist.php?state=$1&c=$2&first=0 

RewriteRule ^(.*)/(.*)/index-(.*).html$ bizlist-alpha.php?state=$1&c=$2&alpha=$3&first=0 

RewriteRule ^(.*)/(.*)/index-(.*)-(.*).html$ bizlist-alpha.php?state=$1&c=$2&alpha=$3&first=$4 

RewriteRule ^(.*)/(.*)/businesses-(.*).html$ bizlist.php?state=$1&c=$2&first=$3 

RewriteRule ^(.*)/(.*)/(.*)-County/(.*)/(.*)/index.htm$ business.php?s=$1&telephone=$5&c=$2 
RewriteRule ^(.*)/(.*)/(.*)-County/(.*)/(.*)/index.htm$ ^(.*)/(.*)/(.*)-County/(.*)/(.*)/index.htm$ 

RewriteRule ^(.*)/(.*)/(.*)-County/(.*)/(.*)/$ business.php?s=$1&telephone=$5&c=$2 
+0

你錯過了最重要的事情:描述你到底想要做什麼!重定向什麼? – deceze

+0

這是問題的最後一段:「我想要的」:我想要的是將所有www.example.com/country/city/county/business-name/listing-id/contact.htm重定向到www.example。 com/country/city/county/business-name/listing-id/index.htm。 –

+0

啊,很難找到內嵌的gobbledygook之中。重新格式化在這裏確實奇妙。 – deceze

回答

1

這應該這樣做:

RewriteRule (.*)/contact.htm$ $1/index.htm [R,L] 

不要讓你的正則表達式超特定當包羅萬象.*會做。你只對最後一部分感興趣,所以只匹配最後一部分。當然,如果您有其他網址以contact.htm結尾,您不想重定向,則需要根據需要更正確地設置正則表達式。

還要注意規則的順序很重要;您需要在任何其他重寫發生之前插入此規則,這將導致它不再匹配。

+0

它的工作!非常感謝兄弟! –