首页 > NGINX > NGINX 301重定向

NGINX 301重定向

股票分析报告网站http://www.65.la在百度的收录都很诡异。65.la的百度收录数量比www.65.la的收录数量还要多一些,这和我的预期不一致。一直以来友情链接和内链都是主打的www.65.la,在google里也是将www.65.la作为首选域名的。但是这个个设置对百度无效,百度的快照甚至有时候是www.65.la是最新的有时候是65.la是最新的额。今天痛下决心,把65.la重定向到www.65.la,在nginx上做如下配置即可实现了:

 

     server
{
   listen       80;
   server_name  www.65.la 65.la;

#下面的红色字体即为301重定向所需要的配置
    if ($host != ‘www.65.la’ ) {
    rewrite ^/(.*)$
http://www.65.la/$1 permanent;
    }
   index index.html index.htm index.php;
   root  /opt/www/65;
   location ~ .*\.(php|php5)?$
   {     
     #fastcgi_pass  unix:/tmp/php-cgi.sock;
     fastcgi_pass  127.0.0.1:9000;
     fastcgi_index index.php;
     include fcgi.conf;
   }
   error_page  404 /404.html;
   log_format  65  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
              ‘$status $body_bytes_sent “$http_referer” ‘
              ‘”$http_user_agent” $http_x_forwarded_for’;
   access_log  /opt/nginx/logs/65.log  65;
}

更改配置文件之后测试:

# /opt/nginx/sbin/nginx –t

重新加载nginx使配置文件的更新生效

# /opt/nginx/sbin/nginx -s reload

检查http头部返回信息

http://www.seoconsultants.com/tools/check-server-headers-tool/#Report

1. REQUESTING: http://65.la
GET / HTTP/1.1
Connection: Keep-Alive
Keep-Alive: 300
Accept:*/*
Host: 65.la
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)
SERVER RESPONSE:
HTTP/1.1 301 Moved Permanently Server: nginx/0.8.46 Date: Sun, 22 May 2011 17:50:18 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://www.65.la/

看到上述信息,可以说明配置成功了。

分类: NGINX 标签: ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.

注意:
评论者允许使用'@user:'的方式将自己的评论通知另外评论者。
例如, ABC是本文的评论者之一,则使用'@ABC:'(不包括单引号)将会自动将您的评论发送给ABC。
user必须和评论者名相匹配,区分大小写。

SEO Powered by Platinum SEO from Techblissonline