Wordpress将所有404更改为410错误代码 [英] Wordpress change all 404 to 410 error code

查看:207
本文介绍了Wordpress将所有404更改为410错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的wordpress网站上有近3000个帖子,最近被删除了.如何显示错误代码410而不是显示错误代码404,而不是显示所有已删除或未找到的帖子和页面?

解决方案

您可以使用此插件会很方便,或者您可以按照给定的步骤来实现,而无需使用任何插件.

  1. 错误410 (或使用您选择的任何名称)创建页面表单WordPress管理面板
  2. 在要显示给用户的页面上写内容.
  3. 发布页面后,您可以从URL获取页面ID
  4. 在活动主题404.php文件中添加给定代码.

404.php

的代码

$custom_410_page_ID = 25;//Error 410 page ID
header($_SERVER["SERVER_PROTOCOL"] . " 410 Gone");
header("Refresh: 0; url=" . get_permalink($custom_410_page_ID));
exit();

现在,当任何人访问您的旧URL或输入任何错误的URL时,它将被重定向到错误410 页面,并将410状态代码重定向到.

参考:将所有404移动到410

希望这会有所帮助!

My wordpress site has nearly 3000 posts that was deleted recently. Instead of showing error code 404, How do I show error code 410 to all deleted or not found posts and pages?

解决方案

You can either use this plugin which will come handy for you, or you can follow the given steps to achieve this without using any plugin.

  1. Create a Page form WordPress Admin panel as Error 410 (or with any name of your choice)
  2. Write your content in that page which you want to show to the user.
  3. After publishing the page you can get the page ID from the URL
  4. Add the given code in your active theme 404.php file.

Code for 404.php

$custom_410_page_ID = 25;//Error 410 page ID
header($_SERVER["SERVER_PROTOCOL"] . " 410 Gone");
header("Refresh: 0; url=" . get_permalink($custom_410_page_ID));
exit();

Now when any on visit your old URL or mistype any URL it will be redirected to Error 410 page with 410 status code to .

Reference: Move All 404 To 410

Hope this helps!

这篇关于Wordpress将所有404更改为410错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆