我有多个旧域需要重定向到新域, 根据以下规则,要么是特定文件夹,要么是新域上的相同url参数:
olddomain1.com/parameter=x - >重定向到newdomain.com/parameter=x
olddomain2.com/ - >重定向到newdomain.com/b
到目前为止,我有这段代码:
RewriteCond %{HTTP_HOST} ^olddomain1\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain1\.com$
RewriteRule ^/?$ "http\:\/\/www\.newdomain\.com\/$1" [R=301,L]
RewriteRule ^$ /a
RewriteCond %{HTTP_HOST} ^olddomain2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain2\.com$
RewriteRule ^/?$ "http\:\/\/www\.newdomain\.com\/$1" [R=301,L]
RewriteRule ^$ /b
问题是,如果尝试加载
http://www.olddomain2.com/
它送我去
http://www.newdomain.com/a
您可以帮助修复此代码以正常工作吗? 感谢
答案 0 :(得分:1)
您可以使用以下规则:
##Redirect "domain1.com" to "/a"##
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain1\.com$
RewriteRule ^$ http://www.newdomain.com/a [R,L]
##Redirect "domain1.com/foo" to "newdoamain/foo"##
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain1\.com$
RewriteRule ^(.+)$ http://www.newdomain.com/$1 [R,L]
##Redirect "domain2.com" to "/a"##
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain2\.com$
RewriteRule ^$ http://www.newdomain.com/b [R,L]
##Redirect "domain2.com/foo" to "newdoamain/foo"##
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain2\.com$
RewriteRule ^(.+)$ http://www.newdomain.com/$1 [R,L]