rewrite 301 replace domain name with a new domain name

本秂侑毒 提交于 2019-12-13 07:32:33

问题


I need some help on mod rewrite 301 , to redirect my old website address to the new address , here is my scenario

ive www.domain1.com/page1/ want to be redirect to domain2.com/page1/

ive to replace all request goes to domain1 with domain2 and keep the page after .com so watever was after .com should be the same just replace domain1 with domain2 . anyone can help me with this Regards


回答1:


You may want to make sure UseCanonicalName is off, lest apache replace hostnames with the site's ServerName.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$    [NC]
RewriteRule ^(.*)$       http://domain2.com$1   [R=301]



回答2:


When redirecting from one domain name to another, you should also take the www prefix into account. This Rewrite rule will match the old domain name with or without the www prefix.

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

or if you prefer to keep the www prefix, substitute this RewriteRule:

RewriteRule ^(.*)$       http://www.newdomain.com/$1   [R=301]


来源:https://stackoverflow.com/questions/2680974/rewrite-301-replace-domain-name-with-a-new-domain-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!