« Discuz!缓存乱码解决一例 Apache Server Status解读之Logging »

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的Rewrite配置》中有个朋友问WordPress如何配置Rewrite,当时也没给个完整正确的答案,最近自己需要Nginx下配置,不得不去解决这个问题。

其实在Nginx下配置WordPress的Rewrite还是比较简单的,在location /{………………}里面加入
if (!-f $request_filename){
rewrite (.*) /index.php;
}
即可实现。

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

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

相关文档
Nginx下Discuz!的Rewrite》:http://www.ccvita.com/319.html
Nginx下WordPress的Rewrite》:http://www.ccvita.com/319.html
Nginx的Rewrite配置》:http://www.ccvita.com/319.html
Nginx的防盗链配置》:http://www.ccvita.com/319.html

“Nginx下WordPress的Rewrite”

8条回复
  1. if (!-e $request_filename) {
    rewrite ^([_0-9a-zA-Z-]+)?(/wp-.*) $2 last;
    rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;
    rewrite ^ /index.php last;
    }

    我的是这样配置的。

  2. 没有评论

  3. @joyqi 看见上面那条评论没有,只是还没有审核而已嘛

  4. IIS下好像不行。

  5. @张家口 这不是IIS下的规则嘛~~~~

  6. WP可以直接自定议REWRITE

  7. WP是可以直接自定议REWRITE,但是你服务器得支持啊

  8. WP是可以直接自定议REWRITE,但是你服务器得支持啊

回复留言

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image

你可以使用XHTML标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>