How to Prevent Redirecting From to Country-Specific Domains

Programming Tutorial – How to Prevent Redirecting From to Country-Specific Domains. Seegatesite will share a tutorial specifically for the blogger user (blogspot) that redirects the subdomain to specific country subdomains.

How to Prevent Redirecting From to Country-Specific Domains

Actually this tutorial are old and many have shared in other sites, but there is no harm if the current share here because at the moment it may be beneficial to you. This tutorial I got from two sources, these are arlina design dan labnol

Note: Not recommended for bloggers who have put Adsense ads on their blogs to use this code. Because it would violate the rules of the Google AdSense policy.

 Lets begin the tutorial prevent redirecting from to country-specific domains below :

1. Open your blogger > Template > Edit HTML > The add this code below

<script type='text/javascript'>
var str=window.location.href.toString();if("-1"==str.indexOf(".com/")){var str1=str.substring(str.lastIndexOf(".blogspot."));if("-1"==str1.indexOf("/"))var str2=str1;else var str2=str1.substring(0,str1.indexOf("/")+1);window.location.href=window.location.href.toString().replace(str2,"")}


<script type="text/javascript">
var blog = document.location.hostname;var slug = document.location.pathname;var ctld = blog.substr(blog.lastIndexOf("."));if (ctld != ".com") {var ncr = "http://" + blog.substr(0, blog.indexOf("."));ncr += "" + slug;window.location.replace(ncr);}

Or this code

    <script type="text/javascript">
          /* Get the full URL of the current blogger page */
          var blog = document.location.href.toLowerCase();
          /* Do not redirect if the domain is .com already */
          if (!blog.match(/\.blogspot\.com/)) {
            /* Replace the country TLD with .com and ncr switch */
            blog = blog.replace(/\.blogspot\..*?\//, "");
            /* Open the new URL in the current tab */

2. Save the template.

Explanation :

When javascript bloggers get the URL of the current page and if it isn’t served from the domain, it will replace the specific country TLD ( or with . It also adds the switch / NCR to force a redirect visitors to address. Now add the code above the location where the visitors who opened your blog, the blog will not be redirect automatically to another blogspot subdomain.

Thus tutorial about how to prevent redirecting from to country-specific domains, hope useful 🙂

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.