为wordpress设置404页面

  • 没有404页面的情况

如果你的主题中不支持404页面,当访问当前域名下不存在的URL时,会出现

Not Found

The requested URL /index.php was not found on this server.

其实在WORDPRESS参考文档里是这么写的 http://codex.wordpress.org/Creating_an_Error_404_Page

What happens if I switch to a theme that does not have a 404.php file?

Visitors clicking on a broken link will just see a copy of the home page of your WordPress site (index.php), but the URL they see will be the URL of the broken link. That can confuse them, especially since there is no acknowledgement of the error. But this is still better than a getting a "NOT FOUND" message without any links or information that could help them find what they seek.

大体意思是

如果使用的主题中不含有404页面会如何?

这时候访问者会看到你WP的首页(index.php),但是域名不会改变(仍是无效的URL)。这会困扰没有相关知识的用户,但仍然比只显示"无法找到"这几个令人不悦的字好。

实际上本人测试的时候并没有显示index.php的内容,不知道是什么情况。

遇到这种令人不悦的情况,我们就迫切想在用户输入无效链接时显示些可以引导用户和抱歉的语句。

  • 建立你自己的404页面

注:以下步骤可能对设置固定链接后的wordpress系统不起作用

  首先你需要新建一个叫404.php的文件,定义无效链接后要显示的内容。方便的做法是复制当前主题的index.php,并把里面的循环语句去掉,加上要显示的语句样式,另存为404.php。

  接着,我们如何让用户输入无效页面时导向的是我们的404.php页面呢?Wordpress帮助文档中是这样描述的。

To tell your web server to use your custom error files, you'll need to edit the .htaccess file in the main directory (where main index.php file resides) of your WordPress installation.

如果你想告诉服务器导向自定义的无效链接页面,需要重新编辑.htaccess文件(指整个wordpress的index.php所属的目录下,不是主题下的index.php)。

在.htaccess问价中添加语句

ErrorDocument 404 /index.php?error=404

  这个语句在你的wordpress文件在服务器根目录下生效,如果你的wordpress文件在一个名叫"wp"的二级目录下,请使用以下语句。

ErrorDocument 404 /wp/index.php?error=404

有关.htaccess

htaccess文件是Apache服务器中的一个配置文件,启用.htaccess,需要修改httpd.conf,修改AllowOverride模式为All,如果httpd.conf的AllowOverride为none,.htaccess文件将被忽略。

 

欢迎访问我们公司的官网 徐州思华科技有限公司 www.sihuakeji.com

posted on 2014-07-03 12:17  iColor我彩  阅读(462)  评论(0编辑  收藏  举报