如何编写.htaccess 301重定向规则

时间:2012-12-16 01:25:37

标签: .htaccess redirect http-status-code-301

我需要重定向以下页面:

www.site.com/austin-tx-key-word-string
www.site.com/austin-tx-different-key-word-string
www.site.com/austin-tx-even-different-key-word-string

全部转到此页面:

www.site.com/austin-tx

1 个答案:

答案 0 :(得分:0)

我认为这样的事情会这样做:

Redirect 301 /austin-tx-key-word-string                 http://www.site.com/austin-tx  
Redirect 301 /austin-tx-different-key-word-string       http://www.site.com/austin-tx 
Redirect 301 /austin-tx-even-different-key-word-string  http://www.site.com/austin-tx

<强> VERSION2

这适用于路径中包含austin-tx的任何网址。它将重定向到:

http://www.site.com/austin-tx

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  ^.*(austin-tx).*$ [NC]
RewriteRule .* %1? [R=301,DPI,L]

<强>版本3

这适用于路径中包含任何one_word_city_name-tx的任何网址。它将重定向到:

http://www.site.com/one_word_city_name-tx

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  ^/([\w]*)-(tx)-.*$ [NC]
RewriteRule .* %1-%2? [R=3-1,DPI,L]
相关问题