Redirect all request from old domain to new domain

冷暖自知 提交于 2019-12-01 03:27:19
Qben

In the configuration (VirtualHost) for each of your olddomain.com host try this:

Redirect permanent / http://newdomain.com/

Apache documentation for Redirect. This is the preferred way when everything should be redirected. If you must use mode_rewrite/htaccess there are plenty of questions around this on SO and one of them is:

How do I 301 redirect one domain to the other if the first has a folder path

EDIT
Recommendation from Apache regarding simple redirects:

mod_alias provides the Redirect and RedirectMatch directives, which provide a means to
redirect one URL to another. This kind of simple redirection of one URL, or a class of 
URLs, to somewhere else, should be accomplished using these directives rather than 
RewriteRule. RedirectMatch allows you to include a regular expression in your 
redirection criteria, providing many of the benefits of using RewriteRule.

Write the below code in to your .htaccess and it will redirect all your old domain request to new domain.

RewriteEngine on
RewriteBase /
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!