Nginx常用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\.html" /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-9]{6})/?([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;
# tags
rewrite ^/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;
# 用户 rewrite ^/uid/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&uid=$1&page=$2 last;
rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last;
# 舆图文件
rewrite sitemap.xml sitemap.php last;
# 自界说链接
rewrite ^(.*)/([0-9a-zA-Z\-\_]+)/?([0-9]+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last;

Discuz 7:

rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page\%3D$3&page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;

Typecho:

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;
    }
}

shopex  启用伪静态

location /
{
  if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php?$1 last;
  }
}

启用伪静态

location /
{
  if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php?$1 last;
  }
}
时间: 2024-08-05 04:44:35

Nginx常用Rewrite伪静态法则的相关文章

Nginx伪静态配置和常用Rewrite伪静态规则

伪静态是一种可以把文件后缀改成任何可能的一种方法,如果我想把php文件伪静态成html文件,这种相当简单的,下面来介绍nginx 伪静态配置方法有需要了解的朋友可参考. nginx里使用伪静态是直接在nginx.conf 中写规则的,并不需要像apache要开启写模块(mod_rewrite)才能进行伪静态. nginx只需要打开nginx.conf配置文件,在server里面写需要的规则即可. 代码如下: server { listen       80; server_name  haha.

nginx常用伪静态设置

nginx里使用伪静态是直接在nginx.conf 中写规则的,并不需要像apache要开启写模块(mod_rewrite)才能进行伪静态. nginx只需要打开nginx.conf配置文件,在server里面写需要的规则即可. 复制代码 代码如下: server { listen       80; server_name  bbs.jb51.net; index index.html index.htm index.php; root  /home/www/bbs; error_page 

Nginx/Apache之伪静态设置 - 运维小结

一.什么是伪静态伪静态即是网站本身是动态网页如.php..asp..aspx等格式动态网页有时这类动态网页还跟"?"加参数来读取数据库内不同资料,伪静态就是做url重写操作(即rewrite).很典型的案例即是discuz论坛系统,后台就有一个设置伪静态功能,开启伪静态后,动态网页即被转换重写成静态网页类型页面,通过浏览器访问地址和真的静态页面没区别.但是记住:做伪静态的前提就是服务器要支持伪静态重写URL Rewrite功能. 考虑搜索引擎优化(即SEO),将动态网页通过服务器处理成

[亲测可用]ShopEx在Nginx上的的Rewrite伪静态规则

Nginx配置ShopEx伪静态其实最简单了.在规则里添加判断是否存在文件或者目录(!-e),然后将它转发给根目录下的index.php进行处理就好了. location / { if (!-e $request_filename) { rewrite ^/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ /index.php?$1 last; } } 如果ShopEx放在其他目录中,只需要将"/"换成相对目录就可以了...例如放在shop文件夹

前端开发掌握nginx常用功能之rewrite

上一篇博文对nginx最常用功能的server及location的匹配规则进行了讲解,这也是nginx实现控制访问和反向代理的基础.掌握请求的匹配规则算是对nginx有了入门,但是这些往往还是不能满足实际的需求场景,例如请求url重写.重定向等等,这都需要对请求的path进行修改操作的,匹配规则是不能独自完成实际需求的,这就需要掌握nginx的另一个常用功能rewrite,下面就来说说这个常用功能. Rewrite规则 rewrite功能就是,使用nginx提供的全局变量或自己设置的变量,结合正

Nginx常用配置实例(4)

Nginx作为一个HTTP服务器,在功能实现方面和性能方面都表现得非常卓越,完全可以与Apache相媲美,几乎可以实现Apache的所有功能,下面就介绍一些Nginx常用的配置实例,具体包含虚拟主机配置.负载均衡配置.防盗链配置以及日志管理等. 一. 虚拟主机配置实例 下面在Nginx中创建三个虚拟主机,需要说明的是,这里仅仅列出了虚拟主机配置部分. http { server { listen          80; server_name     www.domain1.com; acce

Nginx中 Rewrite学习笔记

路由重写是Web服务器中的一个很重要的基本功能.通过路由重写,可以结构化URL,更具语义化(对SEO有益).另外,分享出去的URL可能会因程序路由变动而导致URL失效,而路由的重写可以很好的解决这类问题. 适当的使用Rewrite功能,可以更我们带来很多的好处.Nginx中Rewrite的功能是基于perl语言兼容的正则表达式,所以在编译安装nginx之前,需要安装PREC库.Nginx中Rewrite功能实现是基于ngx_http_rewrite_module,所以确保安装了此模块. Rewr

Nginx系列教程之四:Nginx常用变量汇总及测试

Nginx系列教程之:Nginx内置变量的收集及使用 前言:     各位小伙伴,前两天忙着测试openstack Icehouse,撰写openstack技术文档,导致nginx剩下的几篇博文没来得及整理,你是不是等着急啦?哈哈,抱歉,今天继续来聊一聊nginx常用的内置变量及其相关的使用. Nginx的变量在nginx的使用中还是占了一定的重要性,尤其是在日志和rewrite中,必须对各种变量的含义有所了解,才能组合出适合自己的日志格式和更高级的rewrite规则.其次了解nginx的变量含

nginx下yii伪静态处理

Yii在Nginx下的rewrite配置 今天配置nginx后首页显示正常,点击链接就报404错误,只是知道在apache下只要开启重定向模块,再nginx下加上如下配置即可: 1. Nginx配置 在nginx.conf的server {段添加类似如下代码: Nginx.conf代码: location / { if (!-e $request_filename){ rewrite ^/(.*) /index.php last; } } 2. 在Yii的protected/conf/main.