Post Tags

Tutorials

Pretty posts

redirect website link to another
Now in this tutorial, i will share a tips that help you to redirect one link to another link without loosing any SEO issue. It's very simple and effective way to redirect your favorite link to another link. By this way, we will use javascript and canonical to do this.

Code - Sample code without delay looks like this. Paste this snippet right after opening the head tag to make it work properly.

<link rel="canonical" href="https://yourdomain.com/"/>
<noscript>
    <meta http-equiv="refresh" content="0;URL=https://yourdomain.com/"/>
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
    var url = "https://yourdomain.com/";
    if(typeof IE_fix != "undefined")
    {
        document.write("redirecting...");
        var referLink = document.createElement("a");
        referLink.href = url;
        document.body.appendChild(referLink);
        referLink.click();
    }
    else { window.location.replace(url); }
</script>

https://yourdomain.com/: Change this link with your redirect link. You need to change it 3 times. See above code.

rel="canonical": Search engines don't analyze JavaScript code to see the redirection. We added this meta tag to notify search engines about our redirection.

nocript: We added a noscript section with a HTML refresh meta tag in it, it is a good solution. It has Internet Explorer support to pass the HTTP referrer.

if(typeof IE_fix != "undefined"): We added this to pass the http referrer in IE8 and lower.

if(typeof IE_fix != "undefined"): Don't remove this line or appendChild() will fail because it is called before document.onload to make the redirect as fast as possible. Nobody will see this text, it is only a tech fix.

window.location.replace(url): We added this to redirect support all other browsers.

I think that now your all of redirect work, you can finish with this. Thanks to http://insider.zone/ to make this valuable code.