




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
正则表达式匹配,其中:1. * 为区分大小写匹配2. * * 为不区分大小写匹配3. * !和!*分别为区分大小写不匹配及不区分大小写不匹配文件及目录匹配,其中:1. * -f和!-f用来判断是否存在文件2. * -d和!-d用来判断是否存在目录3. * -e和!-e用来判断是否存在文件或目录4. * -x和!-x用来判断文件是否可执行flag标记有:1. * last 相当于Apache里的L标记,表示完成rewrite2. * break 终止匹配, 不再匹配后面的规则3. * redirect 返回302临时重定向 地址栏会显示跳转后的地址4. * permanent 返回301永久重定向 地址栏会显示跳转后的地址一些可用的全局变量有,可以用做条件判断(待补全)1. $args2. $content_length3. $content_type4. $document_root5. $document_uri6. $host7. $http_user_agent8. $http_cookie9. $limit_rate10. $request_body_file11. $request_method12. $remote_addr13. $remote_port14. $remote_user15. $request_filename16. $request_uri17. $query_string18. $scheme19. $server_protocol20. $server_addr21. $server_name22. $server_port23. $uri结合QeePHP的例子1. if (!-d $request_filename) 2. rewrite /(a-z-A-Z+)/(a-z-A-Z+)/?(.*)$ /index.php?namespace=user&controller=$1&action=$2&$3 last;3. rewrite /(a-z-A-Z+)/?$ /index.php?namespace=user&controller=$1 last;4. break;多目录转成参数/sort/2 = /index.php?act=sort&name=abc&id=21. if ($host * (.*)/.domain/.com) 2. set $sub_name $1; 3. rewrite /sort/(/d+)/?$ /index.php?act=sort&cid=$sub_name&id=$1 last;4. 目录对换/123456/xxxx - /xxxx?id=1234561. rewrite /(/d+)/(.+)/ /$2?id=$1 last;例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下:1. if ($http_user_agent MSIE) 2. rewrite (.*)$ /nginx-ie/$1 break;3. 目录自动加“/”1. if (-d $request_filename)2. rewrite /(.*)(/)$ http:/$host/$1$2/ permanent;3. 禁止htaccess1. location /.ht 2. deny all;3. 禁止多个目录1. location /(cron|templates)/ 2. deny all;3. break;4. 禁止以/data开头的文件可以禁止/data/下多级目录下.log.txt等请求;1. location /data 2. deny all;3. 禁止单个目录不能禁止.log.txt能请求1. location /searchword/cron/ 2. deny all;3. 禁止单个文件1. location /data/sql/data.sql 2. deny all;3. 给favicon.ico和robots.txt设置过期时间;这里为favicon.ico为99天,robots.txt为7天并不记录404错误日志1. location (favicon.ico) 2. log_not_found off;3. expires 99d;4. break;5. 6. 7. location (robots.txt) 8. log_not_found off;9. expires 7d;10. break;11. 设定某个文件的过期时间;这里为600秒,并不记录访问日志1. location /html/scripts/loadhead_1.js 2. access_log off;3. root /opt/lampp/htdocs/web;4. expires 600;5. break;6. 文件反盗链并设置过期时间这里的return 412 为自定义的http状态码,默认为403,方便找出正确的盗链的请求“rewrite / /leech.gif;”显示一张防盗链图片“access_log off;”不记录访问日志,减轻压力“expires 3d”所有文件3天的浏览器缓存1. location * .+/.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ 2. valid_referers none blocked *. *. localhost 94;3. if ($invalid_referer) 4. rewrite / /leech.gif;5. return 412;6. break;7. 8. access_log off;9. root /opt/lampp/htdocs/web;10. expires 3d;11. break;12. 只充许固定ip访问网站,并加上密码1. root /opt/htdocs/www;2. allow 94;3. allow ;4. allow ;5. deny all;6. auth_basic C1G_ADMIN;7. auth_basic_user_file htpasswd;将多级目录下的文件转成一个文件,增强seo效果/job-123-456-789.html 指向/job/123/456/789.html1. rewrite /job-(0-9+)-(0-9+)-(0-9+)/.html$ /job/$1/$2/jobshow_$3.html last;将根目录下某个文件夹指向2级目录如/shanghaijob/ 指向 /area/shanghai/如果你将last改成permanent,那么浏览器地址栏显是/location/shanghai/1. rewrite /(0-9a-z+)job/(.*)$ /area/$1/$2 last;上面例子有个问题是访问/shanghai 时将不会匹配1. rewrite /(0-9a-z+)job$ /area/$1/ last;2. rewrite /(0-9a-z+)job/(.*)$ /area/$1/$2 last;这样/shanghai 也可以访问了,但页面中的相对链接无法使用,如./list_1.html真实地址是/area/shanghia/list_1.html会变成/list_1.html,导至无法访问。那我加上自动跳转也是不行咯(-d $request_filename)它有个条件是必需为真实目录,而我的rewrite不是的,所以没有效果1. if (-d $request_filename)2. rewrite /(.*)(/)$ http:/$host/$1$2/ permanent;3. 知道原因后就好办了,让我手动跳转吧1. rewrite /(0-9a-z+)job$ /$1job/ permanent;2. rewrite /(0-9a-z+)job/(.*)$ /area/$1/$2 last;文件和目录不存在的时候重定向:1. if (!-e $request_filename) 2. proxy_pass ;3. 域名跳转1. server2. 3. listen 80;4. server_name ;5. index index.html index.htm index.php;6. root /opt/lampp/htdocs/www;7. rewrite / /;8. access_log off;9. 多域名转向1. server_name ;2. index index.html index.htm index.php;3. root /opt/lampp/htdocs;4. if ($host c1gstudio/.net) 5. rewrite (.*) $1 permanent;6. 三级域名跳转1. if ($http_host * (.*)/.i/.c1gstudio/.com$) 2. rewrite (.*) $1;3. break;4. 域名镜向1. server2. 3. listen 80;4. server_name ;5. index index.html index.htm index.php;6. root /opt/lampp/htdocs/www;7. rewrite /(.*) /$1 last;8. access_log off;9. 某个子目录作镜向1. location /zhaopinhui 2. rewrite .+ / last;3. break;4. discuz ucenter home (uchome) rewrite1. rewrite /(space|network)-(.+)/.html$ /$1.php?rewrite=$2 last;2. rewrite /(space|network)/.html$ /$1.php last;3. rewrite /(0-9+)$ /space.php?uid=$1 last;discuz 7 rewrite1. rewrite (.*)/archiver/(fid|tid)-/w/-+/.html)$ $1/archiver/index.php?$2 last;2. rewrite (.*)/forum-(0-9+)-(0-9+)/.html$ $1/forumdisplay.php?fid=$2&page=$3 last;3. rewrite (.*)/thread-(0-9+)-(0-9+)-(0-9+)/.html$ $1/viewthread.php?tid=$2&extra=page/%3D$4&page=$3 last;4. rewrite (.*)/profile-(username|uid)-(.+)/.html$ $1/viewpro.php?$2=$3 last;5. rewrite (.*)/space-(username|uid)-(.+)/.html$ $1/space.php?$2=$3 last;6. rewrite (.*)/tag-(.+)/.html$ $1/tag.php?name=$2 last;给discuz某版块单独配置域名1. server_name ;2. 3. location = / 4. if ($http_host news/.$) 5. rewrite .+ /forum-831-1.html last;6. break;7. 8. discuz ucenter 头像 rewrite 优化1. location /ucenter 2. location .*/.php?$3. 4. #fastcgi_pass unix:/tmp/php-cgi.sock;5. fastcgi_pass :9000;6. fastcgi_index index.php;7. include fcgi.conf; 8. 9. 10. location /ucenter/data/avatar 11. log_not_found off;12. access_log off;13. location /(.*)_big/.jpg$ 14. error_page 404 /ucenter/images/noavatar_big.gif;15. 16. location /(.*)_middle/.jpg$ 17. error_page 404 /ucenter/images/noavatar_middle.gif;18. 19. location /(.*)_small/.jpg$ 20. error_page 404 /ucenter/images/noavatar_small.gif;21. 22. expires 300;23. break;24. 25. jspace rewrite1. location .*/.php?$2. 3. #fastcgi_pass unix:/tmp/php-cgi.sock;4. fastcgi_pass :9000;5. fastcgi_index index.php;6. include fcgi.conf; 7. 8. 9. location * /index.php/10. 11. rewrite /index.php/(.*) /index.php?$1 break;12. fastcgi_pass :9000;13. fastcgi_index index.php;14. include fcgi.conf;15. 信赖此刻大部门用Linux VPS的伴侣都在利用这个敏捷传布的Nginx,本日就清算一下最常见的PHP法式的Rewrite(伪静态法则)。Wordpress:location / index index.html index.php;if (-f $request_filename/index.html)rewrite (.*) $1/index.html break;if (-f $request_filename/index.php)rewrite (.*) $1/index.php;if (!-f $request_filename)rewrite (.*) /index.php;PHPCMS:location / #以下为PHPCMS 伪静态化rewrite法则rewrite (.*)show-(0-9+)-(0-9+).html$ $1/show.php?itemid=$2&page=$3;rewrite (.*)list-(0-9+)-(0-9+).html$ $1/list.php?catid=$2&page=$3;rewrite (.*)show-(0-9+).html$ $1/show.php?specialid=$2;#以下为PHPWind 伪静态化rewrite法则rewrite (.*)-htm-(.*)$ $1.php?$2 last;rewrite (.*)/simple/(a-z0-9_+.html)$ $1/simple/index.php?$2 last;ECSHOP:if (!-e $request_filename)rewrite /index.php /index.php last;rewrite /category$ /index.php last;rewrite /feed-c(0-9+).xml$” /feed.php?cat=$1 last;rewrite “/feed-b(0-9+).xml$” /feed.php?brand=$1 last;rewrite “/feed.xml$” /feed.php last;rewrite “/category-(0-9+)-b(0-9+)-min(0-9+)-max(0-9+)-attr(-*)-(0-9+)-(.+)-(a-zA-Z+)(.*).html$” /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;rewrite “/category-(0-9+)-b(0-9+)-min(0-9+)-max(0-9+)-attr(-*)(.*).html$” /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;rewrite “/category-(0-9+)-b(0-9+)-(0-9+)-(.+)-(a-zA-Z+)(.*).html$” /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;rewrite “/category-(0-9+)-b(0-9+)-(0-9+)(.*).html$” /category.php?id=$1&brand=$2&page=$3 last;rewrite “/category-(0-9+)-b(0-9+)(.*).html$” /category.php?id=$1&brand=$2 last;rewrite “/category-(0-9+)(.*).html$” /category.php?id=$1 last;rewrite “/goods-(0-9+)(.*).html” /goods.php?id=$1 last;rewrite “/article_cat-(0-9+)-(0-9+)-(.+)-(a-zA-Z+)(.*).html$” /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;rewrite “/article_cat-(0-9+)-(0-9+)(.*).html$” /article_cat.php?id=$1&page=$2 last;rewrite “/article_cat-(0-9+)(.*).html$” /article_cat.php?id=$1 last;rewrite “/article-(0-9+)(.*).html$” /article.php?id=$1 last;rewrite “/brand-(0-9+)-c(0-9+)-(0-9+)-(.+)-(a-zA-Z+).html” /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;rewrite “/brand-(0-9+)-c(0-9+)-(0-9+)(.*).html” /brand.php?id=$1&cat=$2&page=$3 last;rewrite “/brand-(0-9+)-c(0-9+)(.*).html” /brand.php?id=$1&cat=$2 last;rewrite “/brand-(0-9+)(.*).html” /brand.php?id=$1 last;rewrite “/tag-(.*).html” /search.php?keywords=$1 last;rewrite “/snatch-(0-9+).html$” /snatch.php?id=$1 last;rewrite “/group_buy-(0-9+).html$” /group_buy.php?act=view&id=$1 last;rewrite “/auction-(0-9+).html$” /auction.php?act=view&id=$1 last;rewrite “/exchange-id(0-9+)(.*).html$” /exchange.php?id=$1&act=view last;rewrite “/exchange-(0-9+)-min(0-9+)-max(0-9+)-(0-9+)-(.+)-(a-zA-Z+)(.*).html$” /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;rewrite /exchange-(0-9+)-(0-9+)-(.+)-(a-zA-Z+)(.*).html$” /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;rewrite “/exchange-(0-9+)-(0-9+)(.*).html$” /exchange.php?cat_id=$1&page=$2 last;rewrite “/exchange-(0-9+)(.*).html$” /exchange.php?cat_id=$1 last;SHOPEX:location / if (!-e $request_filename) rewrite /(.+.(html|xml|json|htm|php|jsp|asp|shtml)$ /index.php?$1 last;SaBlog 2.0:# 只带月份的归档rewrite /date/(0-96)/?(0-9+)?/?$ /index.php?action=article&setdate=$1&page=$2 last;# 无分类翻页rewrite /page/(0-9+)?/?$ /index.php?action=article&page=$1 last;# 分类rewrite /category/(0-9+)/?(0-9+)?/?$ /index.php?action=article&cid=$1&page=$2 last;rewrite /category/(/+)/?(0-9+)?/?$ /index.php?action=article&curl=$1&page=$2 last;# 归档、高级搜刮rewrite /(archives|search|article|links)/?$ /index.php?action=$1 last;# 全数批评、标签列表、引用列表 带分页rewrite /(comments|tagslist|trackbacks|article)/?(0-9+)?/?$ /index.php?action=$1&page=$2 last;# tagsrewrite /tag/(/+)/?(0-9+)?/?$ /index.php?action=article&item=$1&page=$2 last;# 文章rewrite /archives/(0-9+)/?(0-9+)?/?$ /index.php?action=show&id=$1&page=$2 last;# RSS rewrite /rss/(0-9+)?/?$ /rss.php?cid=$1 last;rewrite /rss/(/+)/?$ /rss.php?url=$1 last;# 用户 re
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 脑肿瘤分子分型-洞察与解读
- 班组安全培训鉴定材料课件
- 2025年芜湖安定精神病医院招聘护理10人考前自测高频考点模拟试题及答案详解参考
- 2025江苏省退役军人事务厅直属优抚医院招聘12人考前自测高频考点模拟试题完整答案详解
- 2025年甘肃省临夏州东乡县融媒体中心招聘模拟试卷完整参考答案详解
- 2025福建龙岩市上杭县文化旅游发展有限公司(上杭古田建设发展有限公司)所属企业招聘人员拟聘用人选模拟试卷参考答案详解
- 2025内蒙古巴彦淖尔市能源(集团)有限公司招聘48人(第一批)考前自测高频考点模拟试题及一套完整答案详解
- 2025内蒙古阿拉善盟赛汗人力资源服务有限公司招聘10人考前自测高频考点模拟试题附答案详解(模拟题)
- 2025贵州省农业科学院引进高层次人才16人考前自测高频考点模拟试题附答案详解(考试直接用)
- 班组安全培训方法及措施课件
- 2021海康威视DS-AT1000S超容量系列网络存储设备用户手册
- 《童年》整本书解读与教学设计
- 临床医学循环系统试题及答案2025年版
- 甘肃工装装修施工方案
- 户外鱼池用电安全知识培训课件
- 钢筋工程拆除专项方案(3篇)
- 复退军人就业创业课件
- 黑龙江省齐齐哈尔市九校2025-2026学年高三上学期期初联考英语试题(含答案)
- 四级手术术前多学科讨论优化
- 新版2026统编版小学道德与法治三年级上册 第4课《 科技力量大》第1课时 科技改变生活和科技改变观念 教学课件
- 关于2024学宪法讲宪法知识竞赛题目及答案
评论
0/150
提交评论