WordPress——修改固定链接后文章404错误

WordPress博客站点默认固定链接https://www.xxx.com/?p=123,这样的链接有特殊字符,看起来不美观。
改成https://www.xxx.com/%post_id%.html的格式不仅对SEO的有好处,而且链接更美观

一般的大型网站系统,都依赖伪静态。如果服务器的伪静态没有配置好,访问部分链接就会出现404的情况。

方法一

将下面几行if代码copy到server{ } 字段中, 需要添加的代码:

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;
}

保存退出,重启nginx。

方法二

在nginx安装目录找到nginx的配置文件即nginx.conf ,然后进行如下配置就好

location / {
            index  index.php index.html index.htm;

            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;

保存退出,重启nginx。

方法三

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;
}

location / { 
    try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
赞(0) 打赏
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《WordPress——修改固定链接后文章404错误》
文章链接:https://blog.78cat.cn/1864.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

觉得文章有用就打赏一下文章作者

感谢您的支持,我将持续输出干货满满的内容

支付宝扫一扫

微信扫一扫