nginx的一些規則案例備忘

科技小能手發表於2017-11-12

xxx:

http://home.hao123.com/wiki/wiki.asp?/=xxx      301到 http://home.hao123.com/wiki/index/c/xxx

location ~ wiki.asp {

           if ( $query_string ~* “=(d+)$” ) {

               set $cc $1;

               set $args “;

                     #   rewrite ^ $scheme://$host/test/$cc.mp3 permanent;

                    rewrite ^ http://home1.hao123.com/wiki/index/c/$cc  permanent;

               }

       }

http://home.hao123.com/wiki/wikiview.asp?/=xxx  301到 http://home.hao123.com/wiki/view/id/xxx

      location ~ wikiview.asp {

         if  ($query_string ~* “=(d+)$” ) {

               set $cc $1;

               set $args “;

                     #   rewrite ^ $scheme://$host/test/$cc.mp3 permanent;

                    rewrite ^ http://home1.hao123.com/wiki/view/id/$cc  permanent;

               }

       }

1列表頁:http://home.hao123.com/zhuangshi/list.asp  301到  http://jmall.sina.com/Company/cList/

rewrite ^/zhuangshi/list.asp  http://jmall.sina.com/Company/cList/ permanent;

2列表頁:http://home.hao123.com/design/   301到 http://jmall.sina.com/Company/styleList

rewrite ^/design http://jmall.sina.com/Company/styleList permanent;

相簿首頁

http://home.hao123.com/photo/zhuangxiu.asp  301到 http://home.hao123.com/photo/

rewrite ^/photo/zhuangxiu.asp http://home.hao123.com/photo/ permanent;

相簿分類頁

http://home.hao123.com/photo/jiaju.asp   301到 http://home.hao123.com/photo/showlist/pid/6

rewrite ^/photo/jiaju.asp http://home.hao123.com/photo/showlist/pid/6 permanent;

相簿內頁

http://home.hao123.com/photo/phoList.asp?/=xxx   301到 http://home.hao123.com/photo/show/id/xxx#p=1

location ~ /photo/phoList.asp {

           if ( $query_string ~* “=(d+)$” ) {

               set $cc $1;

               set $args “;

                     #   rewrite ^ $scheme://$host/test/$cc.mp3 permanent;

                    rewrite ^ http://home1.hao123.com/photo/show/id/$cc#p=1  permanent;

               }

       }

http://home.hao123.com/photo/list.asp?classId=xxx   301到 http://home1.hao123.com/photo/showlist/cid/xxx

location ~ /photo/list.asp {

           if ( $query_string ~* “=(d+)$” ) {

               set $cc $1;

               set $args “;

                     #   rewrite ^ $scheme://$host/test/$cc.mp3 permanent;

                    rewrite ^ http://home1.hao123.com/photo/showlist/cid/$cc  permanent;

               }

       }

http://home.hao123.com/*** 以上未定義的 直接跳轉到 http://home.hao123.com/

if (!-e $request_filename) {

           rewrite ^(.*)$  http://home1.hao123.com last;

            }  

ps:xxx 代表數字ID


http://ng1.qq.com/tv/list.asp?areaid=33   301 到 http://ng1.qq.com/tv/lists/areaid/33

if ($request_uri ~ “^/tv/list.asp?areaid=([d]+)$”)

       {

          set $q $1;

          rewrite .* /tv/lists/areaid/$q? permanent;

       }



訪問 http://ng.qq.com/html/2013-07-29/1035590.html  內容顯示 http://ng.qq.com/html/2013/07/29/1035590.html

rewrite “^/html/(d+)-(d+)-(d+)/(.*).html$” /html/$1/$2/$3/$4.html last;





http://news.qq.com/index.php?m=html&a=Other&date=130806&par=31MTR1375752599_1  重寫成 http://news.qq.com/html/Other/130806/31MTR1375752599_1.html

rewrite ^(.*)/(w+)/(w+)/(d+)/(w+).html$ $1/index.php?m=$2&a=$3&date=$4&par=$5 last;


訪問 3g.ah.qq.com跳到m.ah.qq.com

if ($host ~* “^3g.(.*).qq.com”) {

set $domain $1;

rewrite ^/(.*)     http://m.$domain.qq.com/$1 last;

}



http://www.ah.cn/newsshow.php?siteid=2&cid=4&id=9&page=1偽靜態成

http://www.ah.cn/newsshow-4-9-1.html

rewrite ^/newsshow-([0-9]+)-([0-9]+)-([0-9]+).html$ /newsshow.php?siteid=2&cid=$1&id=$2&page=$3 last;

本文轉自 liang3391 51CTO部落格,原文連結:http://blog.51cto.com/liang3391/1174610


相關文章