解决Nginx下WordPress后台wp-admin不自动加斜杠问题

题是这样的:我习惯在博客地址后面直接加”wp-admin”敲回车进入wordpress后台,但是进去以后发现不管我点任何一个管理子项,一律404(找不到页面),瞬间我就囧了,这是神马状况。。。
仔细看了一下管理子项的链接,发现他们全是类似”//www.slyar.com/blog/edit.php”这样的,关键就在于他们都少了”/wp-admin/”这条路径,路径都不对了,肯定404呗。。。
知道问题在哪就简单了,而且答案肯定还是在nginx的重定向规则上,但是我不知道怎么改,但是我还知道wordpress官方肯定已经解决了,所以我还是很淡定地去查文档了。。。got it
http://codex.wordpress.org/nginx
# add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
果然给我在codex上找到了解决方案,就是简单地加一行斜杠重定向而已,方法综述如下:
1、登录shell,vim编辑nginx配置目录(一般是在/usr/local/nginx/conf/)下的”wordpress.conf”,当然如果你像我一样用的是自己写的conf文件,那就改对应的那个重定向配置文件就好。
vim?/usr/local/nginx/conf/wordpress.conf
2、把官方给的那一行加到文件最后面就行了
location /blog/ {
if ($host != 'www.slyar.com' ) {
rewrite ^/(.*)$ //www.slyar.com/$1 permanent;
}
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 (.*) /blog/index.php;
}
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
3、:wq保存重启nginx即可
ps.其实你要是懒的话,直接用 “echo >>” 追加就行了= =
echo ‘rewrite /wp-admin$ $scheme://$host$uri/ permanent;’ >> /usr/local/nginx/conf/wordpress.conf
/etc/init.d/nginx restart
上一个:一份关于UI设计的完整介绍(二)
下一个:怎么让公司的网站出类拔萃成为了一个关键问题
昔阳网站建设,昔阳做网站,昔阳网站设计