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

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服务器生效。

点赞