WordPress 404自动跳转到首页教程

今日分享4种方式让WordPress 404自动跳转到首页,使用方法:复制以下代码添加到 文章的404页面 (404.php),即可实现404自动跳转到首页

第一种方法,直接跳转

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

 

第二种方法,直接跳转

<?php
//WordPress 301 跳转到网站首页
wp_redirect(home_url(), 301);
exit;
?>

第三种方法,直接载入首页 返回404 状态

<?php
//直接载入首页 返回 404 状态
global $wp_query;
$wp_query->set_404();
status_header(404);
nocache_headers();
include (get_query_template('index'));
die();
?>

 

第四种方法,返回 404 状态,然后通过 html 刷新跳转到首页

<?php
//返回 404 状态,然后通过 html 刷新跳转到首页
lobal $wp_query;
$wp_query->set_404();
status_header(404);
nocache_headers();
echo '<meta http-equiv="refresh" content="0;url=' . home_url() . '">';
exit;
?>

© 版权声明
THE END
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容