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

Last updated on May 4th, 2018 at 01:43 am

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.

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

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

Did you get the answer you were searching for?

Save hours of searching online or wasting money testing unnecessary plugins, get in touch with me and let's discuss a suitable plan for your project. Best thing about this service is that you are never placed on hold and get to talk to an expereinced Oxwall/Skadate developer.

Get Answers for Free!

Ask a question related to this topic and get immediate answers from other community members in 48hrs or less. Contribute by answering members questions.

Ask Question
Premium Service

Whether it's a custom plugin, theme or dedicated support needed to get you started on your project, get professional 24/7 support tailored to your need.

Get in Touch

Or just leave a comment...

Leave a Reply