[文章作者:张宴 本文版本:v1.1 最后修改:2009.12.01 转载请注明原文链接:http://blog.zyan.cc/bo-blog_nginx_rewrite/]

  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 (!-e $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;
   }


  PS:2009-12-01修正一处错误,之前文章中的if (!-x更换为if (!-e




技术大类 » Web服务器 | 评论(74) | 引用(0) | 阅读(70741)
renyuan
2010-1-25 17:10
wp我个人觉得他的后台太乱了,速度也比较的慢,感觉好像用了很多js样
zzhcool Email
2010-1-31 22:44
你好,我的网站在windows下都是这样的格式
/articles/PHP-safe/ (自定义别名的)
articles/131/

在nginx下用了你这个规则,我把其中的post全部替换为articles了,大部分可以访问,但是有二级目录的文章自定义别名的是404,另外还有tags里面的中文也是404,不知如果换成我以前的articles方式,规则还要怎样修改才能完全正确访问呢
feixu
2010-2-1 11:16
我也不知道 那段规则放在哪里?我放在.htaccess里面 貌似不行。。。。放在哪里?后台开启了 高级URL Rewrite。。。。
为blog添加回复自动生成html的功能 Homepage
2010-5-20 18:24
为blog添加回复自动生成html的功能:

编辑inc/mod_visit.php 文件
找到 else { //Deal with ajax
然后再下面添加:
$site="http://book.shafa.in";
///make html
$postida=str_replace("'","",$plusquery_c);
$postida=str_replace(",","",$postida);
$deldira="post/".$postida;
$deldirs="post/";
if ($deldira != $deldirs) //is post root
{
if(is_dir($deldira)) removeDir($deldira);
$cur_chapcont=file_get_contents($site."/post/".$postida);
if(!is_dir($deldira)) mkdir($deldira);
$fp=fopen("post/".$postida."/index.html","w+");
fwrite($fp,$cur_chapcont);
if ($fp) fclose($fp);
}
///end make html

在文件末尾添加:
//删除目录  
function removeDir($dirName)  
{  
$result = false;  
if(! is_dir($dirName))  
{  
trigger_error("目录名称错误", E_USER_ERROR);  
}  
$handle = opendir($dirName);  
while(($file = readdir($handle)) !== false)  
{  
if($file != '.' && $file != '..')  
{  
$dir = $dirName . DIRECTORY_SEPARATOR . $file;  
is_dir($dir) ? removeDir($dir) : unlink($dir);  
}  
}  
closedir($handle);  
$result = rmdir($dirName) ? true : false;  
return $result;  
}
hancang2000 Email Homepage
2010-6-11 15:44
hi 帅哥,我想有一个rewrite的问题,就是说我要我的所有请求里面任何地方只要有大写字母的都重写为写小字母在nginx的rewrite里面怎么实现
小新
2010-7-19 17:46
张老师,我用这个末成功,有问题想请教,能否留下联系方式?
白癜风 Homepage
2010-8-5 16:54
http://www.xuanti.com/
白癜风 Email Homepage
2010-8-16 14:25
不错  谢谢分享
白癜风 Homepage
2010-8-20 11:01
http://www.tjpf120.comzan
cbzc Homepage
2010-10-9 16:48
进口轴承 Homepage
2010-10-13 16:37
深圳的夜
2010-11-2 14:41
张老师,帮我转下规则,小弟在此谢过 我邮箱:zhanzhiyuan520@163.com

<VirtualHost *:80>
ServerName netjiajia.com
RewriteLogLevel 3
DocumentRoot /home/tom/code/netjiajia
DirectoryIndex  index.jsp
JkMount /*.jsp ajp13
JkMount /*.do ajp13
JkMount /*.html ajp13
JkMount /image* ajp13
JkMount /dwr* ajp13  
JkMount /uploadfile* ajp13  
JkMount /home ajp13
JkMount /swf* ajp13
RewriteEngine on
RewriteCond %{HTTP_HOST} (?!www|bbs|home|admin|cms|image)^[a-z0-9\-]+\.netjiajia\.com$
RewriteRule ^/(.*)$ /%{HTTP_HOST}/$1
RewriteRule  ^/gonglue\.netjiajia\.com/$ /gonglue.html [PT]
RewriteRule  ^/shopping\.netjiajia\.com/$ /shopping.html [PT]
RewriteRule  ^/food\.netjiajia\.com/$ /food.html [PT]
RewriteRule  ^/journey\.netjiajia\.com/$ /journey.html [PT]
RewriteRule  ^/fashion\.netjiajia\.com/$ /fashion.html [PT]
RewriteRule  ^/shenzhen\.netjiajia\.com/$ /city/shenzhen.jsp [PT]
RewriteRule  ^/guangzhou\.netjiajia\.com/$ /city/guangzhou.jsp [PT]
RewriteRule  ^/hangzhou\.netjiajia\.com/$ /city/hangzhou.jsp [PT]
RewriteRule  ^/nanjing\.netjiajia\.com/$ /city/nanjing.jsp [PT]
RewriteRule  ^/zhanjiang\.netjiajia\.com/$ /city/zhanjiang.jsp [PT]
RewriteRule  ^/beijing\.netjiajia\.com/$ /city/beijing.jsp [PT]
RewriteRule  ^/xiamen\.netjiajia\.com/$ /city/xiamen.jsp [PT]
RewriteRule  ^/chongqing\.netjiajia\.com/$ /city/chongqing.jsp [PT]
RewriteRule  ^/huizhou\.netjiajia\.com/$ /city/huizhou.jsp [PT]
RewriteRule  ^/suzhou\.netjiajia\.com/$ /city/suzhou.jsp [PT]
RewriteRule  ^/nanchang\.netjiajia\.com/$ /city/nanchang.jsp [PT]
RewriteRule  ^/shanghai\.netjiajia\.com/$ /city/shanghai.jsp [PT]
RewriteRule  ^/wuhan\.netjiajia\.com/$ /city/wuhan.jsp [PT]
RewriteRule  ^/haikou\.netjiajia\.com/$ /city/haikou.jsp [PT]
RewriteRule  ^/xian\.netjiajia\.com/$ /city/xian.jsp [PT]
RewriteRule  ^/elements\.netjiajia\.com/$ /elements.jsp [PT]
RewriteRule  ^/forum\.netjiajia\.com/$ /club.html [PT]
RewriteRule  ^/daigou\.netjiajia\.com/$ /purchase/list.html [PT]

RewriteRule  ^/accakappa\.netjiajia\.com/$ /acca_kappa4.jsp [PT]
RewriteRule  ^/vip\.netjiajia\.com/$ /sale/hycard.jsp [PT]
RewriteRule  ^/ayi\.netjiajia\.com/$ /shop/ayi.html [PT]
RewriteRule  ^/retail\.netjiajia\.com/$ /retail.jsp [PT]
RewriteRule  ^/brandshop\.netjiajia\.com/$ /shop/brandshop.html [PT]
RewriteRule ^/([a-z0-9\-]+)\.netjiajia\.com/(.*)$  /$2 [PT]
#RewriteEngine on
#RewriteCond %{HTTP_REFERER} !^http://netjiajia.com[/size]/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://netjiajia.com$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://www.netjiajia.com/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://www.chinhkyoula.com$ [NC]
#RewriteRule .*.(gif|jpb|png|css|js|swf|jgp|jpeg|bmp])$ http://www.chkyoula.com [R,NC] 銆€銆€

#SetEnvIfNoCase Referer "^http://netjiajia.com" local_ref=1
#SetEnvIfNoCase Referer "^http://www.netjiajia.com" local_ref=1
#<FilesMatch ".(gif|jpb|png|css|js|swf|jpg|jpeg|bmp)">
#Order Allow,Deny
#Allow from env=local_ref
#</FilesMatch>  
LoadModule jk_module modules/mod_jk.so  
RewriteLog "/usr/local/apache2/logs/rewrite.log"
JkLogFile "/usr/local/tomcat/logs/mod_jk2.log"
JkLogLevel info
</VirtualHost>
而一网 Email Homepage
2010-11-4 17:29
我使用了nginx ,有个问题请教下您,
ecshop的文章重写规则如下
rewrite "^/article-([0-9]+)(.*)\.html$" /article.php?id=$1 last;

我想把其中id=1 2 4 5的页面分别重写成disclaimer.html,这样的自定义名字,下面这样可以吗?
rewrite "^disclaimer\.html" /article.php?id=1 permanent ;
rewrite "^copyright\.html" /article.php?id=2 permanent ;
rewrite "^contactus\.html" /article.php?id=4 permanent ;
rewrite "^aboutus\.html" /article.php?id=5 permanent ;
876878652
2010-11-15 13:58
smile快速 备案 24小时下号 180元  支持淘宝交易
网上购书 Email Homepage
2011-4-9 10:14
很好 学习了哦http://www.goushu88.cn
图书网 Email Homepage
2011-5-17 14:55
http://www.139gou.cn   网上书店 图书网
雷人 Homepage
2011-6-2 21:41
老张,我的为啥404啊?我把rewrite保存为boblog.conf,上传到/usr/local/nginx/conf/boblog.conf,然后在/usr/local/nginx/conf/vhost/3o.cn.conf中调用include boblog.conf;这样没错吧?pw85我就是这样操作的。然后重启lnmp也没报错,(开始报错,后来我下载本地,editplus编辑上传)但是,还是404why??谢谢回复!
血小板减少性紫癜 Homepage
2011-11-14 19:29
感觉后面的东西看不懂啊
coach outlet store Homepage
2011-11-22 16:58
This louis vuitton uk for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this coach outlet store online. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine christian louboutin sale. Purse the elegance in bridal wedding. Enjoy the fashion.
louis vuitton uk Email Homepage
2011-11-22 17:00
Louis Vuitton is one of the world's leading international fashion houses.The catching styles and upmarket qualities endeared louis vuitton uk to almost everyone.louis vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.
分页: 2/4 第一页 上页 1 2 3 4 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]