Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[教程] Nginx常用Rewrite伪静态法则,其中有discuz,ecshop等多个产品

[复制链接]
绝世十二少 发表于 2012-7-27 10:42:40 | 显示全部楼层 |阅读模式
  1. 信赖此刻大部门用Linux VPS的伴侣都在利用这个敏捷传布的Nginx,本日就清算一下最常见的PHP法式的Rewrite(伪静态法则)。

  2. Wordpress:

  3. location / {
  4. index index.html index.php;
  5. if (-f $request_filename/index.html){
  6. rewrite (.*) $1/index.html break;
  7. }
  8. if (-f $request_filename/index.php){
  9. rewrite (.*) $1/index.php;
  10. }
  11. if (!-f $request_filename){
  12. rewrite (.*) /index.php;
  13. }
  14. }

  15. PHPCMS:

  16. location / {
  17. ###以下为PHPCMS 伪静态化rewrite法则
  18. rewrite ^(.*)show-([0-9]+)-([0-9]+)\.html$ $1/show.php?itemid=$2&page=$3;
  19. rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/list.php?catid=$2&page=$3;
  20. rewrite ^(.*)show-([0-9]+)\.html$ $1/show.php?specialid=$2;

  21. ####以下为PHPWind 伪静态化rewrite法则
  22. rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
  23. rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
  24. }

  25. ECSHOP:

  26. if (!-e $request_filename)
  27. {
  28. rewrite "^/index\.html" /index.php last;
  29. rewrite "^/category$" /index.php last;
  30. rewrite "^/feed-c([0-9]+)\.xml$” /feed.php?cat=$1 last;
  31. rewrite “^/feed-b([0-9]+)\.xml$” /feed.php?brand=$1 last;
  32. rewrite “^/feed\.xml$” /feed.php last;
  33. 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;
  34. 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;
  35. 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;
  36. rewrite “^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$” /category.php?id=$1&brand=$2&page=$3 last;
  37. rewrite “^/category-([0-9]+)-b([0-9]+)(.*)\.html$” /category.php?id=$1&brand=$2 last;
  38. rewrite “^/category-([0-9]+)(.*)\.html$” /category.php?id=$1 last;
  39. rewrite “^/goods-([0-9]+)(.*)\.html” /goods.php?id=$1 last;
  40. rewrite “^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$” /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;
  41. rewrite “^/article_cat-([0-9]+)-([0-9]+)(.*)\.html$” /article_cat.php?id=$1&page=$2 last;
  42. rewrite “^/article_cat-([0-9]+)(.*)\.html$” /article_cat.php?id=$1 last;
  43. rewrite “^/article-([0-9]+)(.*)\.html$” /article.php?id=$1 last;
  44. 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;
  45. rewrite “^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html” /brand.php?id=$1&cat=$2&page=$3 last;
  46. rewrite “^/brand-([0-9]+)-c([0-9]+)(.*)\.html” /brand.php?id=$1&cat=$2 last;
  47. rewrite “^/brand-([0-9]+)(.*)\.html” /brand.php?id=$1 last;
  48. rewrite “^/tag-(.*)\.html” /search.php?keywords=$1 last;
  49. rewrite “^/snatch-([0-9]+)\.html$” /snatch.php?id=$1 last;
  50. rewrite “^/group_buy-([0-9]+)\.html$” /group_buy.php?act=view&id=$1 last;
  51. rewrite “^/auction-([0-9]+)\.html$” /auction.php?act=view&id=$1 last;
  52. rewrite “^/exchange-id([0-9]+)(.*)\.html$” /exchange.php?id=$1&act=view last;
  53. 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;
  54. rewrite ^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$” /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;
  55. rewrite “^/exchange-([0-9]+)-([0-9]+)(.*)\.html$” /exchange.php?cat_id=$1&page=$2 last;
  56. rewrite “^/exchange-([0-9]+)(.*)\.html$” /exchange.php?cat_id=$1 last;
  57. }

  58. SHOPEX:

  59. location / {
  60. if (!-e $request_filename) {
  61. rewrite ^/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ /index.php?$1 last;
  62. }
  63. }

  64. SaBlog 2.0:

  65. # 只带月份的归档
  66. rewrite "^/date/([0-9]{6})/?([0-9]+)?/?$" /index.php?action=article&setdate=$1&page=$2 last;
  67. # 无分类翻页
  68. rewrite ^/page/([0-9]+)?/?$ /index.php?action=article&page=$1 last;
  69. # 分类
  70. rewrite ^/category/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&cid=$1&page=$2 last;
  71. rewrite ^/category/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&curl=$1&page=$2 last;
  72. # 归档、高级搜刮
  73. rewrite ^/(archives|search|article|links)/?$ /index.php?action=$1 last;
  74. # 全数批评、标签列表、引用列表 带分页
  75. rewrite ^/(comments|tagslist|trackbacks|article)/?([0-9]+)?/?$ /index.php?action=$1&page=$2 last;
  76. # tags
  77. rewrite ^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&item=$1&page=$2 last;
  78. # 文章
  79. rewrite ^/archives/([0-9]+)/?([0-9]+)?/?$ /index.php?action=show&id=$1&page=$2 last;
  80. # RSS rewrite ^/rss/([0-9]+)?/?$ /rss.php?cid=$1 last;
  81. rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last;
  82. # 用户 rewrite ^/uid/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&uid=$1&page=$2 last;
  83. rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last;
  84. # 舆图文件
  85. rewrite sitemap.xml sitemap.php last;
  86. # 自界说链接
  87. rewrite ^(.*)/([0-9a-zA-Z\-\_]+)/?([0-9]+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last;

  88. Discuz 7:

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

  94. Typecho:

  95. location / {
  96. index index.html index.php;
  97. if (-f $request_filename/index.html){
  98. rewrite (.*) $1/index.html break;
  99. }
  100. if (-f $request_filename/index.php){
  101. rewrite (.*) $1/index.php;
  102. }
  103. if (!-f $request_filename){
  104. rewrite (.*) /index.php;
  105. }
  106. }
  107. 4.8.5 shopex  启用伪静态
  108. ……
  109.     location /
  110.     {
  111.              if (!-e $request_filename) {
  112.              rewrite ^/(.*)$ /index.php?$1 last;
  113.     }
  114.     }
  115. ……

  116. 1.      启用伪静态
  117. ……
  118. ##begin add by guozhenbin 20100727 (use Pseudo-static)
  119.     location /
  120.     {
  121.              if (!-e $request_filename) {
  122.              rewrite ^/(.*)$ /index.php?$1 last;
  123.     }
  124.     }
  125. ##end add by guozhenbin 20100727
  126. ……
复制代码
miao122112 发表于 2012-8-1 16:18:15 | 显示全部楼层
谢谢楼主的分享啊






史上第一暴君  http://www.hxsk.net  武动乾坤txt下载
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-5-17 17:20 , Processed in 0.104094 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表