SEO友好的URL(永久链接)不适用于NGINX上的Wordpress


SEO friendly URL (Permalinks) not working for Wordpress on NGINX

我们在NGINX服务器的子目录中安装了wordpress。我们希望我们的博客URL看起来像www.example.com/blog。单个博客文章的URL应该像www.example.com/sblog/post-name。为此,当我们在wordpress中设置->永久链接菜单并将其从默认值更改为帖子名称时,它会开始出错。但是,当我们将其保留为默认值时,它运行得很好(www.example.com/blog/?p=123)。博客目录安装在nginx的html文件夹下。我们在nginx.conf文件中做了以下条目:

location /blog {
root /usr/share/nginx/html;
index index.html index.php;
try_files $uri $uri/ /index.php?$args;
location ~ '.php$ {
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass   127.0.0.1:9000;
}
}

博客目录安装在与我们主站点(example.com)的文件夹相同的级别。我们做错了什么?

试试这个,

location /blog/ {
    root /usr/share/nginx/html;
    index index.html index.php;
    try_files $uri $uri/ /blog/index.php?$args;
}

也有类似的问题,我在nginx conf中添加了这个问题,使其适用于nginx hhvm 3.21 中的wordpress/index.php/permink url

添加这个供大家参考:

location / {
    ...
    fastcgi_param  SCRIPT_FILENAME $document_root/index.php$fastcgi_script_name;

}

location / {
    rewrite ^/([^'.]+)$ /index.php/$1 break;
}

确保您使用的是fastcgi,而不是服务器版本(在服务器版本中,由于重写,您可能会得到太多重定向)

  • 已测试
  • QA通过
相关文章: