Nginx下WordPress的Rewrite法则

在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;
}
}

WordPress v3.5.2 简体中文版下载

Nginx下WordPress的Rewrite法例

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/10520.html