存档

文章标签 ‘wordpress nginx rewrite’

WordPress在nginx下rewrite规则

2014年3月25日 没有评论

博客重新迁移之后,用nginx代替了原来的Apache服务器,wordpress使用了伪静态,这个就要使用了nginx的url重定向功能,前面的时候只是粗略的做了一个把所有不存在的文件重定向到根目录的index.php的功能。最近发现使用时发现登陆到目录没有指定详细的文件名时会无线重定向,导致页面死掉了!
今天又发现了这个问题,决定解决它,上网查了一下nginx下wordpress的重定向规则,改过之后重启nginx就好了!
我在配置文件/etc/nginx/conf.d/default.conf中做了如下改动:


location / {
 ........
 index index.php index.html index.htm;

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;
}
 }

 

分类: Linux, Web 标签: