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 麻雀虽小,可御可萝五脏俱全.只是简单的 ...
随机推荐
- 检查Chunksum与Chunk Data之间的缓冲区发送到DataNode节点
我们会看到左边"iOS Apps"下面有四个选项:"Certificates"."Identifiers"."Devices&qu ...
- Linux系统布置java项目
一.远程服务器 Linux系统是没有Windows那样可视化的界面的,所以首先我们需要一个远程Linux服务器的软件,有好多种,比较好用的XShell,下载地址:http://rj.baidu.com ...
- Allegro Out Of Date Shapes原因及解决方法
使用Allegro设计PCB板时,查看Status,经常会遇到out of date shapes的警告信息,具体如下: dynamic shape is still out of data or e ...
- InnoDB配置文件复习
1.文件分类 1.参数文件 2.日志文件 3.socket文件 4.pid文件 5.MySQL表文件 6.存储引擎文件 1.参数文件 1.参数内容写在my.cnf中,每次MySQL实例启动时,载入my ...
- <转>C Runtime Library(MSVCRT)来历
(转载)C Runtime Library(MSVCRT)来历 msvcrt.dll (名称:Microsoft C Runtime Library)提供了printf,malloc,strcpy ...
- 【转】JavaScript下对去重算法的优化
本人较懒,直接将链接附上: JavaScript下去重算法优化:http://www.linuxde.net/2013/02/12062.html
- java嵌套类
java有四种嵌套类: 静态内部类,成员内部类,局部内部类,匿名内部类 1)静态内部类: (1)类的申明加上staitc关键字.一般用public修饰 (2)只能访问外部类的静态变量和静态方法.不能访 ...
- Windows 10开机的秘密在哪里
如何查看开机速度 查看开机速度,一定要安装所谓的第三方安全软件么?老子就是不喜欢被安全! Windows自带的事件查看器中记录了系统的一举一动,何必需要别人来监视? 在运行(WinKey+R)中输入e ...
- mysql用户权限设置
1.创建新用户 通过root用户登录之后创建 >> grant all privileges on *.* to testuser@localhost identified by &quo ...
- Byte,TBytes,array of Byte, array[0..9] of byte的区别
Byte前面已经说是存放bit的单元,是电脑内存的基本单位,byte表示0-255中的256个数字 下面为Byte的用法: var B: Byte; // 表示0-255的数字 begin B := ...