HTACCESS重定向 - 旧域到新域,*除*主页?

时间:2011-04-26 15:24:57

标签: .htaccess redirect

我正在使用以下内容将流量从旧域重定向到新域:

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

效果很好,但我需要将直接转到旧网站主页的流量重定向到其他位置。如何添加此例外?

1 个答案:

答案 0 :(得分:1)

尝试使用以下内容:

## Redirect for home page requests
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /oldhomepage.html [R=301,L]

## Redirect for all other requests
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/oldhomepage.html
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

根据您发送主页请求的位置,可能需要更改一些,但实质上,您需要检查每个%{REQUEST_URI}的{​​{1}}内容。

希望这会有所帮助......

相关问题