以谁为师 发表于 2015-6-7 20:57:00

伪静态规则(nginx)

本帖最后由 以谁为师 于 2015-6-7 21:02 编辑

WordPress伪静态
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伪静态
rewrite ^/caipu-(+)-(+)-(+).html /index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3 last;
rewrite ^/content-(+)-(+)-(+).html /index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3 last;
rewrite ^/list-(+)-(+).html /index.php?m=content&c=index&a=lists&catid=$1&page=$2 last;
rewrite ^/tag-([^\.]*)-(+)-(+).html /index.php?m=content&c=tag&catid=$2&tag=$1&page=$3 last;
rewrite ^/comment-(+)-(+)-(+).html /index.php?m=comment&c=index&a=init&commentid=content_$1-$2-$3 last;
rewrite ^/([^\.]*).html /index.php?m=member&c=index&a=$1 last;


DEDECMS伪静态
rewrite "^/index.html$" /index.php last;
rewrite "^/list-(+)\.html$" /plus/list.php?tid=$1 last;
rewrite "^/list-(+)-(+)-(+)\.html$" /plus/list.php?tid=$1&totalresult=$2&PageNo=$3 last;
rewrite "^/view-(+)-1\.html$" /plus/view.php?arcID=$1 last;
rewrite "^/view-(+)-(+)\.html$" /plus/view.php?aid=$1&pageno=$2 last;
rewrite "^/tags.html$" /tags.php last;
rewrite "^/tag-(+)-(+)\.html$" /tags.php?/$1/$2/ last;

Discuz7伪静态
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-(+)-(+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-(+)-(+)-(+)\.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;

DiscuzX伪静态
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-(+)-(+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-(+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-(+)-(+)-(+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-(+)-(+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/(+)-(.+)\.html$ $1/$2.php?rewrite=$3 last;
if (!-e $request_filename) {
return 404;
}

ECSHOP伪静态
if (!-e $request_filename)
{
rewrite "^/index\.html" /index.php last;
rewrite "^/category$" /index.php last;
rewrite "^/feed-c(+)\.xml$" /feed.php?cat=$1 last;
rewrite "^/feed-b(+)\.xml$" /feed.php?brand=$1 last;
rewrite "^/feed\.xml$" /feed.php last;
rewrite "^/category-(+)-b(+)-min(+)-max(+)-attr([^-]*)-(+)-(.+)-(+)(.*)\.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-(+)-b(+)-min(+)-max(+)-attr([^-]*)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;
rewrite "^/category-(+)-b(+)-(+)-(.+)-(+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;
rewrite "^/category-(+)-b(+)-(+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3 last;
rewrite "^/category-(+)-b(+)(.*)\.html$" /category.php?id=$1&brand=$2 last;
rewrite "^/category-(+)(.*)\.html$" /category.php?id=$1 last;
rewrite "^/goods-(+)(.*)\.html" /goods.php?id=$1 last;
rewrite "^/article_cat-(+)-(+)-(.+)-(+)(.*)\.html$" /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;
rewrite "^/article_cat-(+)-(+)(.*)\.html$" /article_cat.php?id=$1&page=$2 last;
rewrite "^/article_cat-(+)(.*)\.html$" /article_cat.php?id=$1 last;
rewrite "^/article-(+)(.*)\.html$" /article.php?id=$1 last;
rewrite "^/brand-(+)-c(+)-(+)-(.+)-(+)\.html" /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;
rewrite "^/brand-(+)-c(+)-(+)(.*)\.html" /brand.php?id=$1&cat=$2&page=$3 last;
rewrite "^/brand-(+)-c(+)(.*)\.html" /brand.php?id=$1&cat=$2 last;
rewrite "^/brand-(+)(.*)\.html" /brand.php?id=$1 last;
rewrite "^/tag-(.*)\.html" /search.php?keywords=$1 last;
rewrite "^/snatch-(+)\.html$" /snatch.php?id=$1 last;
rewrite "^/group_buy-(+)\.html$" /group_buy.php?act=view&id=$1 last;
rewrite "^/auction-(+)\.html$" /auction.php?act=view&id=$1 last;
rewrite "^/exchange-id(+)(.*)\.html$" /exchange.php?id=$1&act=view last;
rewrite "^/exchange-(+)-min(+)-max(+)-(+)-(.+)-(+)(.*)\.html$" /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;
rewrite ^/exchange-(+)-(+)-(.+)-(+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;
rewrite "^/exchange-(+)-(+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2 last;
rewrite "^/exchange-(+)(.*)\.html$" /exchange.php?cat_id=$1 last;
}

PHPWind伪静态
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/(+\.html)$ $1/simple/index.php?$2 last;
SaBlog2.0伪静态
# 只带月份的归档
rewrite "^/date/({6})/?(+)?/?$" /index.php?action=article&setdate=$1&page=$2 last;
# 无分类翻页
rewrite ^/page/(+)?/?$ /index.php?action=article&page=$1 last;
# 分类
rewrite ^/category/(+)/?(+)?/?$ /index.php?action=article&cid=$1&page=$2 last;
rewrite ^/category/([^/]+)/?(+)?/?$ /index.php?action=article&curl=$1&page=$2 last;
# 归档、高级搜索
rewrite ^/(archives|search|article|links)/?$ /index.php?action=$1 last;
# 全部评论、标签列表、引用列表 带分页
rewrite ^/(comments|tagslist|trackbacks|article)/?(+)?/?$ /index.php?action=$1&page=$2 last;
# tags
rewrite ^/tag/([^/]+)/?(+)?/?$ /index.php?action=article&item=$1&page=$2 last;
# 文章
rewrite ^/archives/(+)/?(+)?/?$ /index.php?action=show&id=$1&page=$2 last;
# RSS rewrite ^/rss/(+)?/?$ /rss.php?cid=$1 last;
rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last;
# 用户 rewrite ^/uid/(+)/?(+)?/?$ /index.php?action=article&uid=$1&page=$2 last;
rewrite ^/user/([^/]+)/?(+)?/?$ /index.php?action=article&user=$1&page=$2 last;
# 地图文件
rewrite sitemap.xml sitemap.php last;
# 自定义链接
rewrite ^(.*)/(+)/?(+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last;

SHOPEX伪静态
if (!-e $request_filename) {
rewrite ^/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ /index.php?$1 last;
}

Typecho伪静态
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;
}

Wecenter伪静态
location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

ThinkPHP
server {
    listen       80;
    server_namewww.a.com;
    root /Users/gongwen/myweb/a; # 该项要修改为你准备存放相关网页的路径
    location / {
      indexindex.php index.html index.htm;
         #如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
         if (!-e $request_filename)
         {
            #地址作为将参数rewrite到index.php上。
            rewrite ^/(.*)$ /index.php/$1;
            #若是子目录则使用下面这句,将subdir改成目录名称即可。
            #rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
         }
    }
    #proxy the php scripts to php-fpm
    location ~ \.php {
      include /usr/local/etc/nginx/fastcgi.conf;
                ##pathinfo支持start
                #定义变量 $path_info ,用于存放pathinfo信息
                set $path_info "";
                #定义变量 $real_script_name,用于存放真实地址
                set $real_script_name $fastcgi_script_name;
                #如果地址与引号内的正则表达式匹配
                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                        #将文件地址赋值给变量 $real_script_name
                        set $real_script_name $1;
                        #将文件地址后的参数赋值给变量 $path_info
                        set $path_info $2;
                }
                #配置fastcgi的一些参数
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param PATH_INFO $path_info;
                ###pathinfo支持end
      fastcgi_intercept_errors on;
      fastcgi_pass   127.0.0.1:9000;
    }
}

ruguoruo 发表于 2015-6-26 20:06:45

感谢楼主的分享~

Lucifer 发表于 2015-6-27 05:52:53

支持中国红客联盟(ihonker.org)

xiaoqqf4 发表于 2015-6-27 16:24:06

加油!干倒冰儿和酒仙!

fireworld 发表于 2015-6-27 16:40:43

还是不错的哦,顶了

admin1964 发表于 2015-6-28 09:33:16

还是不错的哦,顶了

wanmznh 发表于 2015-6-28 18:56:53

支持,看起来不错呢!

wtsqq123 发表于 2015-6-28 22:00:35

感谢楼主的分享~

admin1964 发表于 2015-6-28 22:14:02

学习学习技术,加油!

ayang 发表于 2015-6-29 19:37:30

支持,看起来不错呢!
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 伪静态规则(nginx)