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/
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/
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;
}
}
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();
?>
Try this in your 404 file before you call get_header()
<script>
window.location.assign("<?php bloginfo('url')?>")
</script>
<?php exit; ?>