Skip to main content
1 of 11

I also think that location.replace(url) is the best way, but if you want to notify the search engines about you redirection (they don't analyze javascript to see the redirection) you should add the rel="canonical" meta tag to your website.

Adding a noscript section with a html refresh meta tag in it, is also a good solution. I suggest you to use this javascript redirection tool to create redirections. It also have an IE support to pass the http referrer.

A sample code without delay look like this:

<!--Pleace this snippet right after opening the head tag to make it work properly-->
<!--REDIRECTING STARTS-->
<link rel="canonical" href="https://yourdomain.com"/>
<noscript>
<meta http-equiv="refresh" content="0;URL=https://yourdomain.com">
</noscript>
<script type="text/javascript">
    var url = "https://yourdomain.com";
    
    // IE8 and lower fix
    if (navigator.userAgent.match(/MSIE\s(?!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-->