静态Nginx常用Rewrite(伪静态规则)

rewrite规则  时间:2021-01-09  阅读:()

相信现在大部分用Linux VP S的朋友都在使用这个迅速传播的Nginx今天就整理一下最常见的P H P程序的Rewr it e(伪静态规则)。

WordPre s slocation/ {index index.html index.php;if(-f$re que st_filename/inde x.html){rewri te(.*)$1/inde x.html b re ak;

}if(-f$reque st_filename/ind ex.p hp){rewr ite(.*)$1/ind ex.p hp;

}if(!-f$reque st_file name){rewr ite(.*)/inde x.php;

}

}

PHPCMSlocation/ {

###以下为PHP CMS伪静态化rewrite规则rewrite^(.*)s how-([0-9]+)-([0-9]+)\.html$$1/s ho w.php?ite mid=$2&pa ge=$3;rewr i te^(.*)list-([0-9]+)-([0-9]+)\.html$$1/list.php?catid=$2&p age=$3;rewrite^(.*)s how-([0-9]+)\.html$$1/show.php?specia lid=$2;

####以下为P HP W ind伪静态化rewr ite规则rewrite^(.*)-htm-(.*)$$1.php?$2 la st;rewrite^(.*)/s imp le/([a-z0-9\_]+\.html)$ $1/s imp le/inde x.php?$2 la st;

}

EC S HO Pif(!-e$request_filename)

{rewrite "^/ind ex\.html" /inde x.p hp la st;rewrite "^/category$" /index.php last;rewrite "^/fee d-c([0-9]+)\.xml$”/feed.php?c at=$1 last;rewrite“^/fe ed-b([0-9]+)\.xml$”/feed.php?brand=$1 last;rewrite“^/feed\.xml$”/feed.php last;rewr it e“^/c ate gory-([0-9]+)-b([0-9]+)-mi n([0-9]+)-ma x([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.ht ml$”

/catego ry.p hp?id=$1&brand=$2&pric e_min=$3&p rice_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;rewr ite“^/c ate go ry-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-

]*)(.*)\.html$”/cate go ry.php?id=$1&brand=$2&p rice_min=$3&price_max=$4&filte r_at tr=$5 last;

rewr ite“^/c at e go r y-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.ht ml$”

/c ategory.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;rewr ite“^/c ate go ry-([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$”/catego ry.p hp?id=$1&brand=$2 last;rewrite“^/c ategory-([0-9]+)(.*)\.html$”/c atego ry.p hp?id=$1 la st;rewrite“^/goods-([0-9]+)(.*)\.html”/goods.php?id=$1 last;rewr it e“^/artic le_c a t-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$”

/article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;rewrite“^/artic le_cat-([0-9]+)-([0-9]+)(.*)\.html$”/artic le_cat.p hp?id=$1&p age=$2 las t;rewrite“^/artic le_cat-([0-9]+)(.*)\.html$”/artic le_cat.php?id=$1 las t;rewrite“^/artic le-([0-9]+)(.*)\.html$”/artic le.php?id=$1 last;rewr ite“^/bra nd-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-

Z]+)\.html”/brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;rewr i te“^/bra nd-([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.p hp?id=$1&cat=$2 last;rewrite“^/brand-([0-9]+)(.*)\.html”/b rand.php?i d=$1 la st;rewr ite“^/ta g-(.*)\.html”/s earch.php?keywo rds=$1 las t;rewrite“^/s natc h-([0-9]+)\.html$”/s natc h.php?id=$1 last;rewrite“^/group_b uy-([0-9]+)\.html$”/gro up_buy.p hp?act=view&id=$1 las t;rewrite“^/auction-([0-9]+)\.html$”/auction.php?act=view&id=$1 last;rewrite“^/e xc hange-id([0-9]+)(.*)\.html$”/exc hange.p hp?id=$1&a ct=view la st;rewr it e“^/e xc ha nge-([0-9]+)-min([0-9]+)-ma x([0-9]+)-([0-9]+)-(.+)-([a-zA-

Z]+)(.*)\.html$”/e xc hange.php?c at_id=$1&inte gr a l_min=$2&inte gra l_max=$3&p a ge=$4&s ort=$5&order=$6 la st;rewrite^/exc hange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$”

/exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;rewrite“^/e xc hange-([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:locati on/ {if(!-e$request_filename) {rewrite^/(.+\.(html|xml|j so n|htm|php|j sp|asp|shtml))$/ind ex.p hp?$1 last;

}

}

SaBlog2.0 (感谢追寻36[正冰]博客提供)

#只带月份的归档re wr it e "^/d ate/([0-9]{6})/?([0-9]+)?/?$"

/index.php?action=article&setdate=$1&page=$2 last;

#无分类翻页rewrite^/page/([0-9]+)?/?$/index.php?action=article&p age=$1 last;

#分类rewrite^/cate gory/([0-9]+)/?([0-9]+)?/?$/inde x.p hp?acti on=artic le&c id=$1&page=$2last;rew r ite^/c at e gory/([^/]+)/?([0-

9]+)?/?$/index.php?action=article&curl=$1&page=$2 last;

#归档、高级搜索rewrite^/(arc hives|search|artic le|link s)/?$/ind ex.p hp?actio n=$1 la s t;

#全部评论、标签列表、引用列表带分页rewrite^/(comme nts|tags li st|trackbacks|artic l e)/?([0-

9]+)?/?$/index.php?action=$1&page=$2 last;

#ta gs rewrite^/tag/([^/]+)/?([0-9]+)?/?$/index.php?action=article&item=$1&page=$2 last;#文章rewrite^/archive s/([0-9]+)/?([0-9]+)?/?$/index.p hp?action=show&id=$1&page=$2 last;#RSS rewrite^/rss/([0-9]+)?/?$/rss.php?cid=$1 last;rewrite^/rs s/([^/]+)/?$/rss.php?url=$1 last;

#用户rewrite^/uid/([0-9]+)/?([0-9]+)?/?$/index.p hp?ac tio n=artic le&uid=$1&page=$2la st;rewrite^/user/([^/]+)/?([0-9]+)?/?$/index.php?action=article&user=$1&page=$2 last;#地图文件rewrite sitemap.xml sitemap.php last;

#自定义链接rewr ite^(.*)/([0-9 a-zA-Z\-\_]+)/?([0-

9]+)?/?$$1/index.php?action=show&alias=$2&page=$3 last;

Discuz 7rewrite^/arc hiver/((fid|tid)-[\w\-]+\.html)$/arc hiver/inde x.php?$1 la st;rewrite^/forum-([0-9]+)-([0-9]+)\.html$/forumd isp lay.p hp?fi d=$1&pa ge=$2 la st;rewr it e^/thread-([0-9]+)-([0-9]+)-([0-

9]+)\.html$/viewthread.php?tid=$1&extra=p age\%3D$3&page=$2 la st;rewrite^/space-(username|uid)-(.+)\.html$/space.p hp?$1=$2 last;rewrite^/tag-(.+)\.html$/tag.php?name=$1 la st;

Typecholo cation/ {index index.html index.p hp;if(-f$reque st_filename/index.html){rewrite (.*)$1/index.html b reak;

}if(-f$reque st_filename/index.php){rewr ite (.*)$1/inde x.p hp;

}if(!-f$request_filename){rewr ite (.*) /ind ex.p hp;

}

}

今天暂时整理这些 以后不定期更新。

Advinservers:美国达拉斯便宜VPS/1核/4GB/80GB SSD/1Gbps不限流量/月付$2.5/美国10Gbps高防服务器/高达3.5TBDDos保护$149.99元/月

Advinservers,国外商家,公司位于新泽西州,似乎刚刚新成立不久,主要提供美国和欧洲地区VPS和独立服务器业务等。现在有几款产品优惠,高达7.5TB的存储VPS和高达3.5TBDDoS保护的美国纽约高防服务器,性价比非常不错,有兴趣的可以关注一下,并且支持Paypal付款。官方网站点击直达官方网站促销产品第一款VPS为预购,预计8月1日交付。CPU为英特尔至强 CPU(X 或 E5)。官方...

数脉科技8月促销,新客减400港币,BGP、CN2+BGP、阿里云线路低至350元

数脉科技(shuhost)8月促销:香港独立服务器,自营BGP、CN2+BGP、阿里云线路,新客立减400港币/月,老用户按照优惠码减免!香港服务器带宽可选10Mbps、30Mbps、50Mbps、100Mbps带宽,支持中文本Windows、Linux等系统。官方网站:https://www.shuhost.com* 更大带宽可在选购时选择同样享受优惠。* 目前仅提供HKBGP、阿里云产品,香港...

pacificrack:2021年七夕VPS特别促销,$13.14/年,2G内存/2核/60gSSD/1T流量,支持Windows

pacificrack官方在搞2021年七夕促销,两款便宜vps给的配置都是挺不错的,依旧是接入1Gbps带宽,KVM虚拟、纯SSD raid10阵列,支持包括Linux、Windows 7、10、server2003、2008、2012、2016、2019在内多种操作系统。本次促销的VPS请特别注意限制条件,见本文末尾!官方网站:https://pacificrack.com支持PayPal、支...

rewrite规则为你推荐
企业虚拟主机一般的企业应该用什么样的虚拟主机?com域名注册.com的域名注册需要什么证件和资料吗?asp网站空间ASP空间是什么?100m网站空间100M的最好的网站空间价格多少?郑州虚拟主机虚拟主机哪个好点,用过的推荐下河南虚拟主机谁那有好的虚拟主机?虚拟主机测评我们可以用哪些命令来测试一个虚拟主机的好坏?长沙虚拟主机长沙虚拟主机租用 哪里的比较靠谱 朋友介绍湘域互联的 有谁用过广西虚拟主机江西服务器托管,但要接入专线,问了很多代理都说不可以,如何解决?域名解析域名解析是什么意思为什么要域名解析?
域名论坛 国外主机 singlehop yardvps 北京主机 40g硬盘 刀片式服务器 宏讯 沈阳主机托管 atom处理器 lamp什么意思 标准机柜 e-mail server2008 paypal登陆 大硬盘补丁 装修瓦工招聘 宿主机 kosskeb79 网易轻博客 更多