为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

转载于:https://www.cnblogs.com/icolor/p/3822111.html

要在WordPress启用404页面,你可以按照以下步骤进行操作: 1. 打开你的WordPress文件所在的服务器根目录。 2. 在根目录下找到名为".htaccess"的文件,如果没有该文件,则创建一个新的文本文件并将其命名为".htaccess"。 3. 在".htaccess"文件中添加以下代码:\[1\] ``` ErrorDocument 404 /wp/index.php?error=404 ``` 如果你的WordPress文件在一个名为"wp"的二级目录下,请使用以下代码: ``` ErrorDocument 404 /wp/index.php?error=404 ``` 4. 保存并关闭".htaccess"文件。 5. 现在,当访问不存在的页面时,WordPress将会显示你设置404页面。 请注意,修改".htaccess"文件前最好备份一份以防止意外情况发生。此外,如果你使用的是其他插件或主题,可能还需要进行其他设置来启用自定义的404页面。\[2\] #### 引用[.reference_title] - *1* [为wordpress设置404页面](https://blog.csdn.net/weixin_33849942/article/details/93609148)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [利用wordpress添加新页面_wordpress 插件新页面 wordpress 添加新页面](https://blog.csdn.net/weixin_39635657/article/details/113694213)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [WordPress 如何启用 Memcached 内存缓存来提高网站速度](https://blog.csdn.net/weixin_29774611/article/details/113550460)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值