Perfect code to redirect a website to a different page on load

Even though I expect codes like this to be very popular among webmasters, I still feel I should share this here with you. It’s a simple code to redirect a landing page to another page or website.

<link rel="canonical" href=""/>
<meta http-equiv="refresh" content="0;URL=">
<script type="text/javascript">
    var url = "";
    // IE8 and lower fix
    if (navigator.userAgent.match(/MSIEs(?!9.0)/))
        var referLink = document.createElement("a");
        referLink.href = url;
    // All other browsers
    else { window.location.replace(url); }

Paste this code immediately after the opening <html> tag of your web page and replace with the website address you want the page to redirect to.

Leave a Reply