Freewind @ Thoughtworks scala java javascript dart 工具 编程实践 月结 math python english [comments admin] [feed]

(2011-09-13) WordPress 设置301转向

广告: 云梯:翻墙vpn (省10元) 土行孙:科研用户翻墙http proxy (有优惠)

按照以往惯例,网站以www开头,比如www.freewind.me。但是现在的流行又是,不要二级域名,直接freewind.me。问题来了:搜索引擎可能会把www.freewind.me和freewind.me当作两个不同的网站,分别计算权重。

最好的作法就是选定其中的一个作为主域名,另一个设成301转向过来。

在Wordpress中,怎么设?


首先要在域名管理面板中,将freewind.me与www.freewind.me都指向网站所在的ip,如图:

image

如果你新设了域名A记录,需要等一段时间才能生效。

然后找到虚拟主机上的.htaccess文件,其位置如下:

image

如果没有自行创建。在文件中增加以下内容:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.freewind\.me
RewriteRule ^(.*)$ http://freewind.me/$1 [R=permanent,L]

然后测试:curl http://www.freewind.me -I,得到:

HTTP/1.1 301 Moved Permanently
Date: Tue, 13 Sep 2011 05:59:51 GMT
Server: Apache/2
X-Powered-By: PHP/5.2.17
X-Pingback: http://freewind.me/xmlrpc.php
Location: http://freewind.me/
Vary: Accept-Encoding,User-Agent
Content-Type: text/html; charset=UTF-8

果然已经成了301,完工。

comments powered by Disqus