赵新朋:新时代农民工

  • 首页
  • 日常备忘
  • 服务器类
  • 我的收藏
  • 未分类
  • 国外VPS
欢迎你来到猪窝!
  1. 首页
  2. 服务器类
  3. 正文

学习配置Nginx下WordPress的Rewrite规则

2012/01/04 1465点热度 0人点赞 0条评论

Apache

在Apache下,利用mod_rewrite来实现URL的静态化。

.htaccess的内容如下:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Nginx

在上次《Nginx的Rewrite配置》中有个朋友问WordPress如何配置Rewrite,当时也没给个完整正确的答案,最近自己需要Nginx下配置,不得不去解决这个问题。

其实在Nginx下配置WordPress的Rewrite还是比较简单的,在location /{………………}里面加入

if (!-e $request_filename){
rewrite (.*) /index.php;
}

即可实现。

下面是一个完整的vhost的配置文件

server {
listen 80;
server_name chinaz.com down.chinaz.com;
location / {
        index index.html index.htm index.php;
        root /www/wwwroot/chinaz.com;
        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$ {
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:8787;
        fastcgi_param SCRIPT_FILENAME /www/wwwroot/chinaz.com$fastcgi_script_name;
        }
location /ccvita-status {
        stub_status on;
        access_log off;
        }
}

 

标签: nginx rewrite wordpress
最后更新:2017/01/19

Kratos

保持饥渴的专注,追求最佳的品质

点赞
下一篇 >
分类
  • PHP代码
  • 国外VPS
  • 建站技术
  • 我的收藏
  • 日常备忘
  • 服务器类
  • 未分类
2022年 7月
一 二 三 四 五 六 日
 123
45678910
11121314151617
18192021222324
25262728293031
« 6月    
    链接表
    • 西安保洁公司哪家好

    COPYRIGHT © 2021 赵新朋:新时代农民工. ALL RIGHTS RESERVED.

    THEME KRATOS MADE BY VTROIS