开发者

.htaccess old domain to new domain 301 redirect, but only the domain, not it's pages

Let's say I have a domain: A.com, and if someone goes to A.com I want to redirect to B.com.

But if they go to any page on A.com, e.g. A.com/wp-admin/index.php, there will be NO redirect. In short, I just want a simple top level old name to new domain name 301 redirect. (Any specific pages on A.com will be red开发者_如何学JAVAirected to specific pages on B.com one by one).


Here you go:

RewriteEngine On

RewriteCond %{HTTP_HOST} =domain-one.com
RewriteRule ^$ http://domain-two.com/ [R=301,L]
  1. This rule is to be placed in .htaccess in website root folder. If placed elsewhere some small tweaking may be required.

  2. It will redirect hits to domain root only, e.g. http://domain-one.com/ and no other pages.

  3. I have replaced A.com by domain-one.com and B.com by domain-two.com -- it is more realistic/understandable than A & B.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜