wordpress网站遇到404错误常见方法

(33) 2023-10-11 20:12

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说wordpress网站遇到404错误常见方法,希望能够帮助你!!!。

wordpress网站遇到404错误常见方法_https://bianchenghao6.com/blog__第1张

WordPress 404页面跳转到特定页面的方法

第一种方式

打开WordPress网站模版里边的404.php,如果该404.php不存在,那么就新建一个文件叫做404.php,然后拷贝以下代码进这个页面:

<?php

header("Status: 301 Moved Permanently");

header("Location: ".get_bloginfo('url')."#301-redirect-from-404-page");

?>

<?php

header("Status: 301 Moved Permanently");

header("Location: ".get_bloginfo('url')."#301-redirect-from-404-page");

?>

(2013年1月22日更新)不好意思这里第一种方式里边的 header(“Status: 301 Moved Permanently”); 并不会实现真正的301跳转,而是返回了302跳转,现更正如下:

<?php

header("HTTP/1.1 301 Moved Permanently");

header("Location: ".get_bloginfo('url')."#301-redirect-from-404-page");

?>

<?php

header("HTTP/1.1 301 Moved Permanently");

header("Location: ".get_bloginfo('url')."#301-redirect-from-404-page");

?>

上边代码中的#301-redirect-from-404-page,主要用来通过网站统计系统统计哪些流量是来自404页面跳转过来的。

第二种方式

拷贝以下代码到404.php页面里边,可以跳转404页面到任意你设定的页面,替换其中的xxx为你的域名和页面URL即可:

<?php

header("Status: 301 Moved Permanently");

header("Location: ");

?>

<?php

header("Status: 301 Moved Permanently");

header("Location: ");

?>

(2013年1月22日更新)不好意思这里第一种方式里边的 header(“Status: 301 Moved Permanently”); 并不会实现真正的301跳转,而是返回了302跳转,现更正如下:

<?php

header("HTTP/1.1 301 Moved Permanently");

header("Location: ");

?>

<?php

header("HTTP/1.1 301 Moved Permanently");

header("Location: ");

?>

wordpress设置“固定链接”后,页面404错误的解决方法

Apache解决方案:

/etc/httpd/conf/httpd.config 文件

原因一:Apache中的rewrite模块没有开启,去除这一行前面的#号就可以了

LoadModule rewrite_module modules/mod_rewrite.so

原因二:AllowOverride Not Enabled;服务器可能没打开AllowOverride。如果httpd.config的AllowOverride设置的是None,那.htaccess将被忽略。找到以下2处位置并修改:

<Directory />

Options FollowSymLinks

AllowOverride All

</Directory>

<Directory /var/www/html>

# … other directives…

AllowOverride All

</Directory>

修改完成后,要重启Apache才能生效。

service httpd restart

Nginx解决方案:

设置方式是loction / {}中添加配置:

复制代码

#加入如下一条命令即可

try_files $uri $uri/ /index.php?$args;

复制代码

修改完成后重启Nginx服务器生效。

service nginx restart

今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

上一篇

已是最后文章

下一篇

已是最新文章

发表回复