Nginx下WordPress的Rewrite
最近接触WP Super Cache,该插件要求固定链接必须是重写的,故用到Rewrite。
我的是这样配置的:
/usr/local/nginx/conf/rewrite/wordpress.conf
location / {
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;
}
}
然后在虚拟主机文件里添加
include /usr/local/nginx/conf/rewrite/wordpress.conf;
即可。
完整的vhost的配置文件:
server {
listen 80;
server_name me.52fhy.com;
index index.php index.html index.htm;
root /52fhy.com/wordpress/;
location / {
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;
}
}
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /www/log/me.52fhy.com.log;
}
- 2015-12-18 11:42:24更新:
以上rewrite方法导致后台很多菜单无法访问,现更新。原因是:
location / {
#1
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
#2
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
#3
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
对于后台http://me.52fhy.com/wp-admin/options-writing.php这种链接将直接匹配#3,实际上这时候不需要任何匹配。故可在#2前添加
if (-f $request_filename){
break;
}
或者全部更新更新为:
location / {
index index.html index.php;
if (-f $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite . /index.php last;
}
}
另外,在Apache下,利用mod_rewrite来实现URL的静态化。
.htaccess的内容如下:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
参考:
1、Nginx下WordPress的Rewrite - 平凡的世界
http://www.ccvita.com/336.html
2、wordpress后台访问时没有wp-admin报404错误 | 技术部
http://www.jishubu.net/yunwei/linuxyunwei/420.html
Nginx下WordPress的Rewrite的更多相关文章
- nginx下laravel框架rewrite的设置
nginx下laravel框架rewrite的设置 百牛信息技术bainiu.ltd整理发布于博客园 在nginx的vhost站点配置文件中加入以下内容即可 1 2 3 4 5 6 7 8 9 10 ...
- Nginx下wordpress伪静态规则(rewrite)
当我们从apache服务器转向Nginx服务器的时候,它们的伪静态规则就不一样了,所以你熟悉Nginx服务器的伪静态规则,自己写当然也好.但很多网友还是不太了解Nginx服务器的伪静态规则的,而如果你 ...
- 解决Nginx下WordPress后台404的问题
在把这个博客做好后,上传到nginx服务器上却出现问题. 首先是wordpress官方的伪静态是通过.htaccess实现的,但nginx并不支持.htaccess,无奈只好在网上找到wordpres ...
- nginx下wordpress 固定链接问题
情况是这样的, 我的wordpress并不是放在网站的根目录的,而是放在/blog目录下的,然后在wordpress中设置固定链接的时候,每次都出错,用了网上几个方法都不行,后来在http://cod ...
- Yii在nginx下多目录rewrite
开发过程中,在root下有多个程序,采用一个域名,以目录的形式访问,可以采用如下的方法进行url重写: rewrite ^(\/[^\/]+)(.*) $1/index.php$2 last; 意为取 ...
- [转]nginx下的url rewrite
转:http://zhengdl126.iteye.com/blog/698206 if (!-e $request_filename){rewrite "^/index\.html&quo ...
- nginx下配置Yii2 rewrite、pathinfo等
环境说明: 我试用的lnmp安装包安装的nginx,nginx版本是1.14.1 server { listen ; server_name www.baidu.com; #access_log /d ...
- nginx下配置laravel+rewrite重写
server { listen ; server_name ha.d51v.cn; #access_log /data/wwwlogs/access_nginx.log combined; root ...
- nginx的location和rewrite
1 Nginx rewrite基本语法 Nginx的rewrite语法其实很简单.用到的指令无非是这几个 set if return break rewrite 麻雀虽小,可御可萝五脏俱全.只是简单的 ...
随机推荐
- JSTL和EL表达式多重if问题
俾人以前在写一个查询功能时,由于结果状态分好几种,于是页面就用<c:if></c:if>写了一大堆来判断,后来上网查了下资料,发现有个语法类似于多重if,挺方便的,语法是 &l ...
- Android中如何查看so崩溃的log
两种方法: 一.android自带的arm-eabi-addr2line工具 例如, - :: I DEBUG : # pc 0000d766 /system/lib/libtest.so - :: ...
- python3中返回字典的键
我在看<父与子的编程之旅>的时候,有段代码是随机画100个矩形,矩形的大小,线条的粗细,颜色都是随机的,代码如下, import pygame,sys,random from pygame ...
- 接口测试总结<转>
本文主要分为两个部分: 第一部分:主要从问题出发,引入接口测试的相关内容并与前端测试进行简单对比,总结两者之前的区别与联系.但该部分只交代了怎么做和如何做?并没有解释为什么要做? 第二部分:主要介绍为 ...
- eclipse js 引用跳转
引用 http://stackoverflow.com/questions/24505993/the-resource-is-not-on-the-build-path-of-a-javascript ...
- Android应用:StatusBar状态栏、NavigationBar虚拟按键栏、ActionBar标题栏、Window屏幕内容区域等的宽高
一.屏幕中各种栏目以及屏幕的尺寸 当我们需要计算屏幕中一些元素的高度时,或许需要先获取到屏幕或者各种栏目的高度,下面这个类包含了Status bar状态栏,Navigation bar虚拟按键栏,Ac ...
- Java的基本概念
JAVA的方法签名是 参数类型,参数个数,参数顺序,不包括返回值和访问修饰符. 对象序列化:将一个对象编码成一个字节流.
- 转:关于BFC的初步了解以及常见使用
在学习CSS的过程中,掌握一些常用方法或效果实现的原理对于我们的学习来说是很有帮助的.如最常见的清除浮动和取消外边距塌陷时使用overflow:hidden;,在学习初期往往只知道有这种用法,且使用时 ...
- 最小和(min)
题目描述: N 个数排成一排,你可以任意选择连续的若干个数,算出它们的和.问该如何选择才能 使得和的绝对值最小. 如:N=8 时,8个数如下: 1 2 3 4 5 6 ...
- Enable MFA for a user
If you are root/admin account, in order to configure a virtual MFA device, you must have physical ac ...