首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Nginx下WordPress的Rewrite规则

Nginx下WordPress的Rewrite规则

作者头像
lilugirl
发布于 2019-05-26 21:15:22
发布于 2019-05-26 21:15:22
1.8K0
举报
文章被收录于专栏:前端导学前端导学

Apache

在Apache下,利用mod_rewrite来实现URL的静态化。 .htaccess的内容如下:

代码语言:javascript
复制
# 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 /{………………}里面加入

代码语言:javascript
复制
if (!-e $request_filename){
rewrite (.*) /index.php;
}

即可实现。

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

代码语言:javascript
复制
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;
        }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档