php - 在 Wordpress 中删除 404 状态
问题描述
在 WordPress 中,我修改了我的 404 页面,因此该页面根据用户在 url 中键入的内容显示提要。因此,如果他键入mywebsite.com/orange
并且我在网站上没有此页面,我的脚本将搜索orange
并搜索结果,并且文章将显示在 404 页面上。
但是,我被 Adwords Campaign 禁止了,因为我的网站返回了许多 404 错误。如何在 404.php 页面中禁用 404 状态,以便 Google 不会认为那/orange/
是 404。我希望 404.php 就像一个布局。(所以从技术上讲,我的网站不能有 404 )。
解决方案
您应该能够通过过滤设置的标头来做到这一点。这样的事情会阻止所有 404 标头被发送。
function theme_block_404($header, $code, $description, $protocol)
{
if (intval($code) === 404) { //Is this a 404 header?
$description = get_status_header_desc(200); //Get the default 200 description
return "{$protocol} 200 {$description}"; //Return a 200 status header
} else { //This isn't a 404 status
return $header; //Don't change the header
}
}
add_filter('status_header', 'theme_block_404');
请记住,这有点麻烦,因为它可以防止任何 404 错误被抛出。如果这适合您的情况,那就太好了,否则,您可能希望向此函数添加额外的逻辑,以使其在范围内更加具体。
推荐阅读
- json - 使用 Bash 从纪元以来的毫秒数获取日期
- python - 进程在 Pycharm 中以退出代码 -1073741819 (0xC0000005) 完成
- reactjs - 是的(使用 formik 和 react) - 无法验证数组长度
- javascript - TypeError:props.addToCart 不是函数
- python - 如何匹配两个数据框的列中的值?
- python - 从字典制作字典
- dataframe - Julia 中 @sync @async 的并行性
- python - Django python分页总是显示前2页和最后2页
- android - Kotlin 如何在 EditText Android Studio 中找到确切的单词
- sas - 在 SAS 的数据步骤中,如何获取以字符串形式表示的列名称的列的值?