符合SEO的nginx url规则配置

server
{
                charset utf-8;
                client_max_body_size 128M;

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

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

                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;

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

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

                    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;

                    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;

                    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;


                    #老页面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;

 

写的不够详细,只是做个记录而已。

 

 

转载于:https://my.oschina.net/u/435872/blog/795442

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值