Redirecting a page to the same page under a different domain

天涯浪子 提交于 2020-02-25 09:53:30

问题


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

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