redirect broken pages 404 on wordpress redirection

2019-09-19 14:16发布

问题:

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/

回答1:

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;
   }
}


回答2:

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();
?>


回答3:

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

<script>
  window.location.assign("<?php bloginfo('url')?>")
</script>
<?php exit; ?>


标签: wordpress