符合SEO的nginx url規則配置

server
{
                charset utf-8;
                client_max_body_size 128M;php

                listen 80;
                server_name www.aa.com aa.com;
                index index.html index.htm index.php;
                root  /home/wwwroot/default/aa;css

                if ($host = "aa.com"){
                    rewrite ^/(.*)$ http://www.aa.com redirect;
                }html

                rewrite_log off;
                error_log /home/wwwlogs/aa.error.log notice;
                
                rewrite ^/invest$ /invest/ permanent;
                #我要投資
                location /invest/ {
                    rewrite ^/invest/list\.html$ /invest/ permanent;
                    rewrite ^/invest/list-p([\d]+)-s([\d]+)\.html$ /invest/all/p$1.html permanent;nginx

                    rewrite ^/invest/list-1\.html$ /invest/fangchandiya/ permanent;
                 rewrite ^/invest/list-1-p([\d]+)-s([\d]+)\.html$ /invest/fangchandiya/p$1.html permanent;git

                    rewrite ^/invest/list-2\.html$ /invest/cheliangdiya/ permanent;
                    rewrite ^/invest/list-2-p([\d]+)-s([\d]+)\.html$ /invest/cheliangdiya/p$1.html permanent;web

                    rewrite ^/invest/list-3\.html$ /invest/zhaiquanzhuanran/ permanent;
                    rewrite ^/invest/list-3-p([\d]+)-s([\d]+)\.html$ /invest/zhaiquanzhuanran/p$1.html permanent;微信

                    rewrite ^/invest/list-1-([\d]+)-([\d]+)-([\d]+)\.html$ /invest/fangchandiya/$1-$2-$3.html permanent;
                    rewrite ^/invest/list-1-([\d]+)-([\d]+)-([\d]+)-p([\d]+)-s([\d]+)\.html$ /invest/fangchandiya/$1-$2-$3-$4.html permanent;cookie

                    rewrite ^/invest/list-2-([\d]+)-([\d]+)-([\d]+)\.html$ /invest/cheliangdiya/$1-$2-$3.html permanent;
                    rewrite ^/invest/list-2-([\d]+)-([\d]+)-([\d]+)-p([\d]+)-s([\d]+)\.html$ /invest/cheliangdiya/$1-$2-$3-$4.html permanent;svn

                    rewrite ^/invest/list-3-([\d]+)-([\d]+)-([\d]+)\.html$ /invest/zhaiquanzhuanran/$1-$2-$3.html permanent;
                    rewrite ^/invest/list-3-([\d]+)-([\d]+)-([\d]+)-p([\d]+)-s([\d]+)\.html$ /invest/zhaiquanzhuanran/$1-$2-$3-$4.html permanent;url


                    #老頁面SEO跳轉
                    #http://www.aa.com/invest/list-1-1-3.html
                    rewrite ^/invest/list-([\d]+)-([\d]+)-([\d]+)\.html$ /invest/all/$1-$2-$3.html permanent;
                    #http://www.aa.com/invest/list-1-1-1-p2-s10.html
                    rewrite ^/invest/list-([\d]+)-([\d]+)-([\d]+)-p([\d]+)-s([\d]+)\.html$ /invest/all/$1-$2-$3-$4.html permanent;
                    ######


                    rewrite ^/invest/all/?$ /index.php/invest/all.html last;
                    rewrite ^/invest/all/p([\d]+)\.html$ /index.php/invest/all/p$1.html last;
                    rewrite ^/invest/all/([\d]+)-([\d]+)-([\d]+)\.html$ /index.php/invest/all/$1-$2-$3.html last;
                    rewrite ^/invest/all/([\d]+)-([\d]+)-([\d]+)-([\d]+)\.html$ /index.php/invest/all/$1-$2-$3-$4.html last;

                    rewrite ^/invest/fangchandiya/?$ /index.php/invest/fangchandiya.html last;
                    rewrite ^/invest/fangchandiya/p([\d]+)\.html$ /index.php/invest/fangchandiya/p$1.html last;
                    rewrite ^/invest/fangchandiya/([\d]+)-([\d]+)-([\d]+)\.html$ /index.php/invest/fangchandiya/$1-$2-$3.html last;
                    rewrite ^/invest/fangchandiya/([\d]+)-([\d]+)-([\d]+)-([\d]+)\.html$ /index.php/invest/fangchandiya/$1-$2-$3-$4.html last;

                    rewrite ^/invest/cheliangdiya/?$ /index.php/invest/cheliangdiya.html last;
                    rewrite ^/invest/cheliangdiya/p([\d]+)\.html$ /index.php/invest/cheliangdiya/p$1.html last;
                    rewrite ^/invest/cheliangdiya/([\d]+)-([\d]+)-([\d]+)\.html$ /index.php/invest/cheliangdiya/$1-$2-$3.html last;
                    rewrite ^/invest/cheliangdiya/([\d]+)-([\d]+)-([\d]+)-([\d]+)\.html$ /index.php/invest/cheliangdiya/$1-$2-$3-$4.html last;

                    rewrite ^/invest/zhaiquanzhuanran/?$ /index.php/invest/zhaiquanzhuanran.html last;
                    rewrite ^/invest/zhaiquanzhuanran/p([\d]+)\.html$ /index.php/invest/zhaiquanzhuanran/p$1.html last;
                    rewrite ^/invest/zhaiquanzhuanran/([\d]+)-([\d]+)-([\d]+)\.html$ /index.php/invest/zhaiquanzhuanran/$1-$2-$3.html last;
                    rewrite ^/invest/zhaiquanzhuanran/([\d]+)-([\d]+)-([\d]+)-([\d]+)\.html$ /index.php/invest/zhaiquanzhuanran/$1-$2-$3-$4.html last;
                    
                    rewrite ^/invest/([^\.\/]+)\.html$ /index.php/invest/$1.html last;
                    rewrite ^/invest/?$ /index.php/invest/all.html last;
                    break;
                }

                #老的問答,由於以前SEO已經被收錄,爲了避免至於被關小黑屋,因此留着。
                rewrite ^/wenda$ /wenda/ permanent;     
                location /wenda/ {
                    rewrite ^/wenda/?$ /index.php/wenda/index.html last;
                    rewrite ^/wenda/([^\.\/]+)\.html$ /index.php/wenda/$1.html last;
                    rewrite ^/wenda/view-([^\.\/]+)/?$ /index.php/wenda/view-$1.html last;
                    rewrite ^/wenda/view-([^\/]+)/?$ /index.php/wenda/view-$1 last;
                    rewrite ^/wenda/view(.*)$ /index.php/wenda/view.html last;
                    break;
                }

                #新的問答,符合SEO規則。
                rewrite ^/ask/index.html$ /ask/ permanent;
                rewrite ^/ask$ /ask/ permanent;                
                location /ask/ {
                    rewrite ^/ask/?$ /index.php/ask/index.html last;
                    rewrite ^/ask/([^\.\/]+)/?$ /index.php/ask/$1.html last;
                    rewrite ^/ask/([^\.\/]+)\.html$ /index.php/ask/$1.html last;
                    rewrite ^/ask/([\w]+)/([^\.\/]+)\.html$ /index.php/ask/$1/$2.html last;

                    #rewrite ^/ask\/cate-([^\.\/]+)/?$ /index.php/ask/cate-$1.html last;
                    #rewrite ^/ask\/cate-([^\/]+)/?$ /index.php/ask/cate-$1 last;
                    #rewrite ^/ask\/cate/?$ /index.php/ask/cate-0.html last;

                    rewrite ^/ask/view-([^\.\/]+)/?$ /index.php/ask/view-$1.html last;
                    rewrite ^/ask/view-([^\/]+)/?$ /index.php/ask/view-$1 last;
                    rewrite ^/ask/view(.*)$ /index.php/ask/view.html last;
                    break;
                }                

                #顯示.txt|.xml|.pdf文件
                location ~ .*\.(txt|xml|pdf)$
                {
                    break;
                }

                location / {
        # 手機端顯示 微信頁面              
                if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
                      set $mobile_request '1';
                }
                if ($http_cookie ~ 'mobile_request=full') {
                      set $mobile_request '';
                }
                if ($mobile_request = '1') {
                  # rewrite ^.+ http://h5.aa.com/h.html$uri;
            }
                    rewrite (.*) /index.php$1 last;
                    break;
                }

                #error_page   404   /404.html;

                location ~ \.php.*$
                {
                    include pc.fastcgi.conf;
                    include pc.pathinfo.conf;
                }

                location /nginx_status {
                        stub_status on;
                        access_log   off;
                }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                {
                        expires      30d;
                }

                location ~ .*\.(js|css)?$
                {
                        expires      1h;
                }

                location ~ /\.(ht|svn|git) {
                        deny all;
                }

                access_log  /home/wwwlogs/aa-access.log  logstash;
                error_log   /home/wwwlogs/aa-error.log;
}    
 

其中pc.pathinfo.conf裏面有對頁面url地址的設置,供上面的匹配規則使用。

fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO       $path_info;
try_files $fastcgi_script_name =404;

 

寫的不夠詳細,只是作個記錄而已。

相關文章
相關標籤/搜索