问题
I am changing domain names and want to set up a structure like so:
If a user accesses www.olddomain.com/page, he will be re-directed to www.newdomain.com/page, etc. In other words, only the pre-slash part of the domain would change. I want to do this for all pages under the old domain.
Does anyone know how I can configure this?
回答1:
Can do this a number of ways in the htaccess file in the document root of your old domain. If the old and new domains are on different servers, or at least different document roots, then you can simply use mod_alias' redirect:
Redirect 301 / http://www.newdomain.com/
If you have some confusion about sharing folders between the domains or they reside in the same document root, you'll need to check the HTTP HOST field and use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
来源:https://stackoverflow.com/questions/31735697/redirecting-a-page-to-the-same-page-under-a-different-domain