IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

Bo-Blog 2.1.1 的 Nginx Rewrite 规则[原创]

回忆未来 2009-11-30 16:21:57 累计浏览 7,442 次
本机暂存

  Bo-Blog是一款采用PHP开发的单用户博客程序,本人的博客也采用的是Bo-Blog,个人觉得bo-blog的排版、易用性要比WordPress好得多,但扩展性不如WordPress。

  很多朋友向我询问过,Bo-Blog的Nginx Rewrite规则如何写。由于Bo-Blog官网只提供了Apache的Rewrite规则,这里,我将自己从 Bo-Blog 的 Apache Rewrite 规则转换而来的 Bo-Blog 2.1.1 的 Nginx Rewrite 重写规则贴在此处,供需要的朋友使用:

以下是代码片段:
   if (!-x $request_filename)
   {
      rewrite ^/post/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?entryid=$1&page=$2&part=$3 last;
      rewrite ^/page/([0-9]+)/([0-9]+)/?$ /index.php?mode=$1&page=$2 last;
      rewrite ^/starred/([0-9]+)/?([0-9]+)?/?$ /star.php?mode=$1&page=$2 last;
      rewrite ^/category/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=category_$1&mode=$2&page=$3 last;
      rewrite ^/archiver/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=archive&cm=$1&cy=$2&mode=$3&page=$4 last;
      rewrite ^/date/([0-9]+)/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=showday_$1-$2-$3&mode=$4&page=$5 last;
      rewrite ^/user/([0-9]+)/?$ /view.php?go=user_$1 last;
      rewrite ^/tags/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /tag.php?tag=$1&mode=$2&page=$3 last;
      rewrite ^/component/id/([0-9]+)/?$ /page.php?pageid=$1 last;
      rewrite ^/component/([^/]+)/?$ /page.php?pagealias=$1 last;

      #Force redirection for old rules
      rewrite ^/read\.php/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
      rewrite ^/post/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
      rewrite ^/post/([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/ permanent;
      rewrite ^/post/([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/$3/ permanent;
      rewrite ^/index\_([0-9]+)\_([0-9]+)\.htm$ http://$host/page/$1/$2/ permanent;
      rewrite ^/star\_([0-9]+)\_([0-9]+)\.htm$ http://$host/starred/$1/$2/ permanent;
      rewrite ^/category\_([0-9]+)\.htm$ http://$host/category/$1/ permanent;
      rewrite ^/category\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/category/$1/$2/$3/ permanent;
      rewrite ^/archive\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/ permanent;
      rewrite ^/archive\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/$3/$4/ permanent;
      rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/ permanent;
      rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/$4/$5/ permanent;

      #Filename alias
      rewrite ^/([a-zA-Z0-9_-]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?blogalias=$1&page=$2&part=$3 last;
   }

同分类推荐文章

  1. Vibe新开源项目 - Vaala AI Gateway (2026-05-17 02:10:19)
  2. SmartPerfetto 架构文章 Q&A:8 个深度技术问答 (2026-04-10 11:00:00)
  3. 让 AI 把我的 PHP 博客重写成 Go (2026-03-27 18:33:54)

查看更多 后端 文章 →

建议继续学习

  1. 配置Nginx+uwsgi更方便地部署python应用 (累计阅读 106,963)
  2. 使用gettext来支持PHP的多语言 (累计阅读 39,181)
  3. 搜狐闪电邮箱的 Nginx/Postfix 使用模式 (累计阅读 33,821)
  4. WordPress插件开发 -- 在插件使用数据库存储数据 (累计阅读 29,083)
  5. Paypal接口详细代码(PHP版,非API接口) (累计阅读 19,340)
  6. 记录一个软中断问题 (累计阅读 16,885)
  7. 解析nginx负载均衡 (累计阅读 16,503)
  8. 我的PHP,Python和Ruby之路 (累计阅读 13,061)
  9. include(“./file.php”)和include(“file.php”)区别 (累计阅读 12,720)
  10. 15个最好的免费开源电子商务平台 (累计阅读 12,461)