Nginx配置WordPress的rewrite规则

By | 2018年5月10日

Apache的默认规则为:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

换成nginx,在server端中加入如下规则:

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