Web Site Design by Rainbo Design

Using Tracking Codes in Links

Google treats query strings (ie. the stuff after the question mark) as a part of the URL in the links it follows. So, it sees two URLs pulling up the same content and will consider one or the other as a duplicate. This can lead to real trouble when you change affiliate tracking systems or any other navigation aid that relied on adding a Query String to an important URL on your site. The solution is simple. See the article below.


Removing Tracking Codes for Search Engines

The most common solution is to set up server code 301 redirects from the version of the URL that includes a query string to the same URL without it. The method you use to do this depends on the server software that your host uses. On an Apache-based server, you could use the following code in an .htaccess file:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*)$ http://www.yoursite.com/$1? [R=301]

Of course, this might not be the best solution in every case. Using a tracking code certainly implies the use of a counting mechanism, and simple redirects to the same URL with the query string removed will not always get the job done. If all you need is the entry in your server log file in order to manage the task, then you don't need to do anything more. However, if your tracking system relies on software to handle the counting, then you need an intermediary step.

There are a couple of ways to handle this situation, but I think the simplest is to simply let mod-rewrite re-route the request to a counting script with the information embedded in the request URL for that script. Then, once the script has run to completion, it can seamlessly emit the 301 redirect to the destination page. I'm thinking the .htaccess code would be something like:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*)$ http://www.yoursite.com/cgi-bin/counter.cgi?q=%{QUERY_STRING}&p=$1?

Once you've installed the redirect, be sure to test it with my HTTP Server Response Header Checker. Enter a URL for your site that includes the tracking code and make sure it returns the proper response code, including the new "Location:" URL.

You can also use the new tools provided by Google and Yahoo! to tell them to ignore specific query string parameters, or use the simpler rel="canonical" tag. You'll find more information about both of these methods in my Search Engine Canonicalization article.


This SEO Tip by Rainbo Design was last updated on June 25, 2011



Need More Help?
You'll find more SEO Tips on the menu on the right side of this page.
You can also contact me with your SEO questions.

If you can't fix your website search engine problems on your own, my Search Engine Optimization Services can give your website what it needs to get your fair share of search engine traffic quickly, without disturbing your website's design, and without breaking your budget.

Call Richard L. Trethewey at Rainbo Design in Minneapolis today at 612-408-4057 from 9:00 AM to 5:00 PM Central time
to get started on your affordable website design package or search engine optimization program today!




 Comments or Questions?
 Contact Rainbo Design
  Share This Page!