Categories
技术讨论

网站域名迁移后如何最好的进行重定向

更换域名对于一个网站来说绝对是兵家大忌,如果处理不好可能会将以前的建设成果毁于一旦。这里面必然涉及到一个页面重定向的问题,如何才能尽量减少损失呢?

页面重定向的方法有多种,比如简单的网站迁移公告,网页跳转,自动转向等。在搜索引擎决定一切的今天,最重要的就是如何让搜索引擎理解并处理网站的迁移。使用页面永久性移走(301重定向)是最理想最安全的方法。

从搜索引擎角度出发,当遇到301重定向的时候,搜索引擎将只对新网址进行索引,并把旧地址下的原有外部链接转移到新的地址下,从而不会影响网站的索引和排名。

如何正确的实施301重定向,根据系统和web服务器的不同方法略有不同,一般都是使用rewrite或者redirect指令:

1. 对于apache服务器可以有几种途径:

    a)使用.htaccess文件,在其中增加301指令。(可以使用rewrite或者redirect指令)

    RewriteEngine on

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

   或者

    RedirectMatch ^(.*)$ http://www.ucosoft.com/$1 [R=301,L]

  b) 在httpd.conf中设定

<VirtualHost *>
RewriteEngine on
RewriteRule ^(.*)$ http://www.ucosoft.com$1 [R=301,L]
ServerName www.satwe.com
</VirtualHost>

或者

<VirtualHost *>
#RedirectMatch ^(.*)$ http://www.ucosoft.com$1
ServerName www.satwe.com
</VirtualHost>

2. 如果是虚拟主机,或者其它原因不支持.htaccess或者服务器设置,可以采用ASP或者PHP的方法来实现:

Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”http://www.ucosoft.com/
Response.End

PHP:

header(“HTTP/1.1 301 Moved Permanently”);
header(“Location:http://www.ucosoft.com/“);
exit();

另外还可以是用CNAME的形式来对域名进行操作,但是对于一般的虚拟主机来说,并不支持CNAME转向过来的请求,很可能是给一个404的错误。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.