How to Remove utm_source & Other Parameters From Your URLs

[Edit: I had to remove the script from my site as it seems WordPress 3.6 redirection interferes with it so that countless additional pages get created. Remove yours too in case you use WordPress!]

These days it’s a quite common and very annoying habit by a few services to attach utm_source and other parameters to your internet address aka URL. It’s not only that.

Basically anybody can add anything as an parameter to your URL and make it appear as if it’s part of your blog or site.

Just try adding

  • “?gay-porn”
  • “?obama=muslim”
  • “?you-suck”

to any of your URLs or other sites’ URLs. Most sites accept that without even showing an error “not found”.

In case you link such an URL Google would even index it. So you can make Google show up fake URLs on other people’s websites this way.

Also unwanted parameters break a lot of things SEO-wise. You get unlimited duplicate content this way. People bookmark the wrong (polluted) URLs on Delicious and elsewhere and thus you lose juice on social media.

Who adds utm_source to your URLs and why?

utm_source is added by multiple services in order to get tracked in Google Analytics. You get inflated numbers on Google Analytics though. That’s why I do not recommend adding such parameters to your URLs in the first place. For instance when I click an URL on Delicious which is tagged utm_source=feedburner it gets wrongly counted as stemming from Feedburner and not Delicious as the Delicious bookmark is still tagged as Feedburner and not Delicious.

Also as I said before the bookmarks on Delicious do not add up. It means that maybe 30 people bookmark the Feedburner tagged URL. 30 others bookmark a Twitter tagged URL for the same post and a few dozens others bookmark the original URL. Thus your post doesn’t show up in popular lists.

You can prevent Feedburner from adding the utm_source crap but that’s not enough to remove all other unwanted parameters from your URL. Thus I wrote this tiny script in JavaScript you can add to your WordPress blog anywhere in the header:


<script language="JavaScript" type="text/javascript">
<!--
var url = self.location.href;
var p = url.indexOf("?");
var str = url;
var parameter = str.slice(p);
if (p >= 1 && parameter.indexOf("p") != 1 && parameter.indexOf("s") != 1)
{
url = str.slice(0,p);
self.location.replace(url);
}
//-->
</script>

I know it’s quite redundant and not very elegant but my JavaScript skills haven’t been used much in the last decade so you are welcome to customize it.

The script basically checks where the parameter starts and removes everything from the URL including the question mark “?”

which signifies the start of the parameters. It then redirects visitors on the client-side to the accurate URL without parameter crap in the address.

So in the end your visitor ends up on the actual URL s/he should end up from the beginning but someone else prevented them due polluting the URL with parameter spam.

The only acceptable parameters are the “p” so that you can still use the post preview function in your WordPress and “s” for the search function.

I’ve added the script to SEO 2.0 already so a link like this one should get redirected: http://seo2.0.onreact.com/?you-suck

[Edit: I had to remove the script from my site as it seems WordPress 3.6 redirection interferes with it so that countless additional pages get created. Remove yours too in case you use WordPress!]