如何将404页面重定向到WordPress中的主页

404’s are part of every website. A while ago we compiled a list of some pretty cool WordPress 404 designs. When coding a one page site, you might not have the time to create a custom 404 page. In which case, you might as well redirect the 404 page to your site’s homepage. In this article, we will show you how to redirect 404 page to home page in WordPress.

404是每个网站的一部分。 不久前,我们编制了一些非常酷的WordPress 404设计列表。 对一页网站进行编码时,您可能没有时间创建自定义404页面。 在这种情况下,您最好将404页面重定向到您网站的首页。 在本文中,我们将向您展示如何在WordPress中将404页面重定向到主页。

All you have to do is open your 404.php file in your theme’s folder. If it doesn’t exist, then create a blank php file. Paste the following code in there:

您所要做的就是在主题文件夹中打开404.php文件。 如果不存在,则创建一个空白的php文件。 在其中粘贴以下代码:


<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>

That’s all. Now when a user hits a 404 page will be redirected to the homepage.

就这样。 现在,当用户点击404页面时,将被重定向到首页。

Note: This should be used in very specific cases. In most other cases (i.e blogs, portfolios etc), you should track your 404 pages and redirect them appropriately.

注意:应在非常特殊的情况下使用。 在大多数其他情况下(例如,博客,投资组合等),您应该跟踪404页面并适当地重定向它们

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-redirect-your-404-page-to-the-home-page-in-wordpress/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值