wordpress设置permalinks为postname后打开页面报404错误

1. 博客环境

  • CentOS7
  • 使用lnmp安装nginx ,mysql和php,然后安装wordpress

2. 错误描述

设置permalinks为postname后,博客主页可以打开,但每个博客点进去会报404错误

3. 解决方法

通过编辑nginx.conf,加入一些规则可以解决这个问题

通过lnmp安装nginx ,mysql和php后,nginx.conf 的位置为"/usr/local/nginx/conf/nginx.conf"

vi /usr/local/nginx/conf/nginx.conf

在nginx.conf里面找到“root /websit/wwwroot/;” 这一段,然后在下面添加如下内容:

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;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

按ESC+:wq保存退出

然后重启nginx

/etc/init.d/nginx restart

问题解决。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容