Disable country domain redirects

I'm getting annoyed at my web traffic stats being all messed up because the URLs aren't being counted properly.

Popular Pages - Twigs Tech Tips

People browsing from different part of the world are being redirected to their government friendly top level domains (TLD's) and it's just annoying.

This is meant to be the internet, a place where information roams free from the slow red tape of bureaucracy.

Thankfully, there's a quick fix for this and it doesn't involve any unnecessary pain.

  • Firstly, log in to your admin.
  • Secondly, open up the dashboard for your blog.
  • Click "Template"
  • Click "Edit HTML"
  • Click "Proceed"
  • Select "Expand Widget Templates" at the top.
  • Using your browser, search for </head>
  • Just before that, paste this in:
<script type="text/javascript">
function check_redirect(your_domain) {
if ('.').pop() != your_domain.split('.').pop()) {
var new_url = window.location.href;
new_url = new_url.replace(window.location.protocol + "//" + window.location.hostname, window.location.protocol + "//" + your_domain + "/ncr");
window.location.href = new_url;

  • Change the 2nd last line to whatever you want your domain to be. In this case, I want to enforce it so everyone visits the .au one.
  • Click save.
  • Test it out!


Originally I found the information from here, but from inspection it doesn't seem to cover all the domains I have been seeing in the stats such as

I've rewritten it a little so it does the domain detection and replacement better.

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog