nginx的一些规则案例 备忘

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;

你可能感兴趣的:(规则,nginx,案例)