繁体   English   中英

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

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

我们在NGINX服务器的子目录中安装了wordpress。 我们希望我们的博客URL看起来像www.example.com/blog。 各个博客文章的网址应类似于www.example.com/blog/post-name。 为此,当我们转到wordpress中的setting-> permalinks菜单并将其从Default更改为Post Name时,它开始出现错误。 但是,当我们将其保留为默认值时(www.example.com/blog/?p=123),它就可以正常工作。 Blog目录安装在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/permalink url

添加此以供大家参考:

location / {

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


}

要么

location / {

    rewrite ^/([^\.]+)$ /index.php/$1 break;

}

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

  • 经测试
  • 质量检查合格

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM