现在的位置: 首页 > 综合 > 正文

nginx 301重定向,无www,www

2013年04月27日 ⁄ 综合 ⁄ 共 1038字 ⁄ 字号 评论关闭

由于网站需要,把不带www和带www的域名合并到一起,而新网的又没有了转向功能,只能由服务器下手。谷歌知道需要使用301定向。以便phodal.com转向www.phodal.com

原来的配置文件如下

server
      {
          listen       80;
          server_name phodal.com www.phodal.com;
          index index.html index.htm index.php default.html default.htm default.php;
          root  /home/wwwroot/onelone.com;

          include typecho.conf;
          location ~ .*\.(php|php5)?$
                  {
                          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;
                  }

          access_log off;
      }

将phodal.com删除再添加

server {
    server_name phodal.com;
    rewrite ^(.*) http://www.phodal.com$1 permanent;
}

由于最后就如下所示:

(转载请保留;Phodal's 博客)

server
      {
          listen       80;
          server_name www.phodal.com;
          index index.html index.htm index.php default.html default.htm default.php;
          root  /home/wwwroot/onelone.com;

          include typecho.conf;
          location ~ .*\.(php|php5)?$
                  {
                          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;
                  }

          access_log off;
      }
server {
    server_name phodal.com;
    rewrite ^(.*) http://www.phodal.com$1 permanent;
}

抱歉!评论已关闭.