redirect broken pages 404 on wordpress redirection

2019-09-19 14:10发布

how do you redirect broken pages with a 404 error to the home page in wordpress without using a plugin?

This is what I have so far:

Redirect 301 /404.php http://www.businessbid.ae/resource-centre/home/

标签: wordpress
3条回答
爷、活的狠高调
2楼-- · 2019-09-19 14:51

Try this in your 404 file before you call get_header()

<script>
  window.location.assign("<?php bloginfo('url')?>")
</script>
<?php exit; ?>
查看更多
Rolldiameter
3楼-- · 2019-09-19 14:54

This should be the best way to solve with WordPress (add to functions.php):

add_action('template_redirect','chk_404_redirect');

function chk_404_redirect() {
   if(is_404()) {
      wp_redirect( home_url() ); exit;
   }
}
查看更多
够拽才男人
4楼-- · 2019-09-19 15:12

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:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>
查看更多
登录 后发表回答