Nginx下WordPress的Rewrite规则

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下配置WordPress的Rewrite还是比较简单的,在location /{………………}里面加入如下代码即可实现

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

下面是一个完整的vhost的配置文件,可以参考一下

server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
index index.html index.htm index.php;
root /www/wwwroot/yourdomain;
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/yourdomain$fastcgi_script_name;
}
location /ccvita-status {
stub_status on;
access_log off;
}
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注