I have setup a custom 404 page here
I have edited the .htaccess file for the 404 page to work.
What I want is to redirect a visitor to the home page automatically after a short delay on the 404 page, when he clicks on a non-existing link.
I have setup a custom 404 page here
I have edited the .htaccess file for the 404 page to work.
What I want is to redirect a visitor to the home page automatically after a short delay on the 404 page, when he clicks on a non-existing link.
Use meta refresh tag in 404 page
<meta http-equiv="refresh" content="3;URL='http://www.example.com/404.html'" />
it will redirect according to content value(in seconds) and the URL where you want to redirect
You should use a client side redirection method to apply the proper delay. If you want to support browsers with disabled JavaScript, just paste a META refresh
into a noscript
element. It is better to place it inside a noscript
element because search engines give a penalty for usual META refresh
links.
If the redirect is permanent, I suggest you to use the canonical
tag too to keep the link-juice of missing pages.
This JavaScript redirect generator is a good way to go. The code pasted from there. It also has an IE 8 and lower fix to pass the HTTP referer, which is useful for traffic analysis.
<!-- Pleace this snippet right after opening the head tag to make it work properly -->
<!-- This code is licensed under GNU GPL v3 -->
<!-- You are allowed to freely copy, distribute and use this code, but removing author credit is strictly prohibited -->
<!-- Generated by http://insider.zone/tools/client-side-url-redirect-generator/ -->
<!-- REDIRECTING STARTS -->
<link rel="canonical" href="https://example.com/"/>
<noscript>
<meta http-equiv="refresh" content="5;URL=https://example.com/">
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
var url = "https://example.com/";
var delay = "5000";
window.onload = function ()
{
setTimeout(GoToURL, delay);
}
function GoToURL()
{
if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
{
var referLink = document.createElement("a");
referLink.href = url;
document.body.appendChild(referLink);
referLink.click();
}
else { window.location.replace(url); } // All other browsers
}
</script>
<!-- Credit goes to http://insider.zone/ -->
<!-- REDIRECTING ENDS -->
Just add a little PHP to your 404 error page.
I assume you have this in your htaccess
file, ErrorDocument 404 /error/404/
So on /error/404
you can do the following anywhere.
<?php
header("refresh:5; url=/wherever.html");
?>
Be sure to change 5
to your seconds and wherever.html
to your pat.