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;

本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/1174610


相关文章
|
6天前
|
自然语言处理 前端开发 应用服务中间件
nginx的Location语法规则
nginx的Location语法规则
|
9月前
|
缓存 前端开发 应用服务中间件
|
10月前
|
前端开发 应用服务中间件 API
Nginx 反向代理 去除 路径匹配规则url
Nginx 反向代理 去除 路径匹配规则url
|
6天前
|
应用服务中间件 网络安全 nginx
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
|
6天前
|
Kubernetes 应用服务中间件 网络安全
kubernetes中Ingress Nginx 常用规则使用
kubernetes中Ingress Nginx 常用规则使用
18 0
|
7月前
|
应用服务中间件 nginx 数据安全/隐私保护
安装Nginx报错:make: *** 没有规则可以创建“default”需要的目标“build”。 停止。
安装Nginx报错:make: *** 没有规则可以创建“default”需要的目标“build”。 停止。
200 0
|
6天前
|
数据采集 应用服务中间件 nginx
百度搜索:蓝易云【nginx一些常用user_agent的匹配规则】
这个规则将会根据user_agent中是否包含"Android"、"iPhone"或"iPad"等关键词,将根目录的访问重定向到/mobile/目录下。需要注意的是,使用if指令可能会导致性能下降,建议尽量使用map模块进行user_agent的匹配。在编写规则时,应该确保匹配规则的准确性,以免误判或产生意外的结果。
62 0
|
6月前
|
应用服务中间件 nginx
nginx中handle模块的编写小案例
nginx中handle模块的编写小案例
nginx中handle模块的编写小案例
|
6月前
|
应用服务中间件 程序员 Shell
后端程序员不得不会的 Nginx 转发匹配规则
后端程序员不得不会的 Nginx 转发匹配规则
|
7月前
|
运维 Java 应用服务中间件
【Nginx用法】nginx location正则表达式写法,详解Nginx location 匹配规则(很详细哦)
【Nginx用法】nginx location正则表达式写法,详解Nginx location 匹配规则(很详细哦)
94 0