我最近准备使用Nginx+php-fpm搭建WordPress平台。

安装完成后准备启用友好形式的永久链接,但是经过种种尝试和查资料后,都不能成功。

Nginx没有Apache特有的mod_rewrite,因此不能由WordPress自动配置。

查资料时发现网上流传广泛的解决方案都不管用。

 

下面给出我的解决方案。

首先参照Apache2的.htaccess文件:

RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]

翻译成Nginx的rewrite规则如下:

location /wordpress/ {
    rewrite ^index\.php$ - last;

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

已经经过实践验证了。:-)

相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2022-01-13
  • 2021-06-05
  • 2021-08-11
  • 2022-12-23
  • 2021-07-23
  • 2021-05-18
猜你喜欢
  • 2022-12-23
  • 2021-07-20
  • 2021-12-02
  • 2021-05-11
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案