|
本帖最后由 lenf 于 2013-3-13 09:21 编辑
为什么要做301重定向? 一、为了网址URL的标准化 我们经常遇到的就是带www的域名和不带www的域名301重定向问题。在未做301重定向之前,无论是用户或搜索引擎蜘蛛,通过这两个网址是都能访问网站的同一个页面。对于用户可能不太在意,因为无论用哪个网址都能访问。但是对于搜索引擎来说就是2个不同的URL,意味着2个页面的权重就要分别计算了,最终结果就是网站权重的分散。那么从SEO的角度分析,镜像页面的存在危害也很大。以前提到了在发外链的时候URL带不带www的问题。同样某网站首页http://www.xxx .com/portal.php与 http://www.xxx .com/;还有以/index.asp /default.asp /index.php等形式结尾的首位网址,在未做301永久重定向之前,访问2个网址同样是看到同一个首页,同样是权重分散的问题。这些都是网站优化的过程中必须解决的问题。 二、网站启用了新域名 由于某些原因网站启用了新域名,老域名这时候也需要301重定向到新的域名。这样可以告诉搜索引擎网址启用了新的网址或者是用户访问原来的网址不至于打不开而损失了流量。我们还关心的一个问题就是老域名的权重是否能传递?权重的传递是需要一个过程的,一般谷歌的反应比百度迅速。至于权重是否能够完全传个人认为是不会的。至少我还没有看到关于301重定向能够完全传递权重这一说法的有效案例
下面我介绍一下在nginx上设置301重定向。
没开启301重定向之前:
server
{
listen 80;
server_name yunvn.com www.yunvn.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/yunvn;
include discuzx.conf;
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location /nginx-status
{
stub_status on;
access_log off;
}
error_page 404 = /404.htm;
access_log /home/wwwlogs/yunvn.com.log yunvn.com;
}
做301跳转我们只需要把yunvn.com删除然后在最后面添加:
server {
server_name yunvn.com;
rewrite ^(.*) http://www.yunvn.com$1 permanent;
}
做好301之后的配置文件:
server
{
listen 80;
server_name www.yunvn.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/yunvn;
include discuzx.conf;
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location /nginx-status
{
stub_status on;
access_log off;
}
error_page 404 = /404.htm;
access_log /home/wwwlogs/yunvn.com.log yunvn.com;
}
server {
server_name yunvn.com;
rewrite ^(.*) http://www.yunvn.com$1 permanent;
}
这样当用户输入yunvn.com时就会自动跳转到www.yunvn.com
|
|