• Nginx服务器301跳转到带www的域名的方法


    为什么要这么做?

        我们的域名在做解析时经常会解析2个域名,即带www的和不带www的。这样做的目的是,当用户使用不带www的域名时,也可以正常访问你的网站。但是这样做的后果是,你站点主域名的PR值分散到其他几个URL上了。因为在搜索引擎看来,带www和不带www的URL是2个完全不同的URL,当它们指向同一个网站时,会让搜索引擎不懂应该选择哪一个URL作为主要的域名。如果你用301重定向把其他几个URL如baidu.com转到www.baidu.com时,相应的PR也就集中在主域名:www.baidu.com上了。

    永久跳转和临时跳转

        301永久跳转,当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息中的状态码的一种,表示本网页永久性转移到另一个地址。

        302临时跳转,也是状态码的一种,意义是暂时转向到另外一个网址。

        二者的区别主要是,一句话,302容易被搜索引擎视为spam,301则不会。permanent代表301永久跳转,改为redirect则为302临时跳转。

    如何实现配置?

    server {
      listen 80;
      server_name test.cn;
      return 301 http://www.test.cn$request_uri;
    }
    
    server {
      listen 80;
      server_name www.test.cn;
      root /var/www/test.cn/test_shop/public_html;
      index index.html index.php;
    
      location ~ .*.(php|php5)?$
      {
        #fastcgi_pass unix:/tmp/php-cgi.sock;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
      }
    
      location ~ .*/.(gif|jpg|jpeg|png|bmp|swf|ico) {
        expires 1d;
      }
      location ~ .*.(js|css)?$ {
         expires 1d;
      }
    
    }
  • 相关阅读:
    (转)在WPF中自定义控件 CustomControl (下)注意TemplatePartAttribute
    [STAThread]的含义
    Exception of Storyboard in controlTemplate,can't use binding or dynamic resource
    What is the difference between CollectionView and CollectionViewSource?
    EssentialWPF_chapter6_Data
    WPF 调试方法, WPF Debug
    System.Windows.Markup.ContentPropertyAttribute
    Layout相关
    When use registerReadonly
    注意:匿名事件处理函数
  • 原文地址:https://www.cnblogs.com/itsharehome/p/7168367.html
Copyright © 2020-2023  润新知