[转]WordPress在Nginx中启用Apache的mod_rewrite

其实不是真的可以另到 Nginx 支持 Apache 的 mod_rewrite 的.因为如果你的web服务器是 Nginx ,那么你的 WordPress 就会提示你的服务器环境不支持 mod_rewrite 了,但实际上是支持的,例如安装了 WP Super Cache 这插件就有这样的提示了,现在我们只要添加一行代码就可以关闭这个提示,欺骗WordPress ,让它认为是支持 mod_rewrite 方法是在主题的 functions.php 文件添加下面的代码:

add_filter('got_rewrite', 'nginx_has_rewrites');
function nginx_has_rewrites() {
    return true;
}

另外,因为Nginx运行PHP是用PHP-FPM的,所以有时会导致WordPress认为php没有写权限,表现为无法自动升级,和升级插件等,下面这个代码可以修改这个错误.

add_filter('filesystem_method', 'nginx_make_filesystem_direct');
function nginx_make_filesystem_direct() {
    return 'direct';
}

来自:http://imcat.in/wordpress-on-nginx-apache-mod_rewrite-enabled/

发表回复

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


此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据