nginx支持.htaccess文件实现rewrite方法
作者:CQman 发布时间:September 26, 2010浏览:113847 分类:主机域名
在Google上搜索的资料很多人都说nginx目前不支持.htaccess文件,我按照nginx的规则试验了一下,结果发现 nginx是完全支持.htaccess文件的!方法如下:
1. 在需要使用.htaccess文件的目录下新建一个.htaccess文件,
2. 在里面输入规则,我这里输入Discuz的伪静态规则:
# nginx rewrite rule3. 修改nginx配置文件:
rewrite ^(.*)/archiver/((fid|tid)-[w-]+.html)$ $1/archiver/index.php?$2 last;
rewrite ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3 last;
rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3 last;
rewrite ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3 last;
rewrite ^(.*)/tag-(.+).html$ $1/tag.php?name=$2 last;
# end nginx rewrite rule
vi /etc/nginx/nginx.conf4. 在需要添加伪静态的虚拟主机的server{}中引入.htaccess文件,如图所示:

include /var/www/html/xxx/bbs/.htaccess;(把这个改成你.htaccess文件的具体位置)
wq保存退出。
5. 重新加载nginx配置文件:
/etc/init.d/nginx reload
OK,结束。赞助商链接
坑爹啊!根本就是用nginx的include而已,写法还是一样的啊
有差吗?根本就是用nginx的include写法而已。无奈了。
@雨帆
嗯,就是语法不同吧