重定向htaccess中的动态地址


Redirecting dynamic addresses in 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

应该这样做:

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

不要让你的正则表达式过于特定,如果一个通用的.*就可以。你只对最后一部分感兴趣,所以只匹配最后一部分。当然,如果您有其他以contact.htm结尾的 url,而您不想重定向,则需要适当地使正则表达式更具体。

还要注意规则的顺序很重要;您需要在任何其他重写发生之前插入此规则,否则将导致它不再匹配。