Remove SID query from Magento URLs

Many people wonder why sometimes the SID part appears in their Magento URLs. This is when your URL has additional SID query usually at the end. Take a look at the image. The curiosity is that it does not appear always. What is the most common scenario it happens? You didn’t access the site with the same domain variant you entered as your “Base URL” in your System> Configuration> Web interface.

When you decide to launch the site, you have to decide whether you will market http://www.domain.com/ URL or http://domain.com/. This is an important decision and you shouldn’t change your mind quite often. Search engines usually treat those two URLs as a different sites and therefore the Page Rank potential can be split between those two URLs. So, think about whether you will use www or not and stick by this decision.

Once you decided, go to your System> Configuration> Web interface and enter the desired form to “Base URL” field. When you access the site you will notice that there are no “SID”s when the URL matches the value from “Base URL” field and they appear when it does not.

Now, we want the ability that the site redirects to proper URL once accessed. Someone can place a wrong link to some forum or blog. We don’t want those links to lead to improper URL and we don’t want SIDs to appear to those visitors. Most important: We don’t want that search engines index the URLs with SIDs.

The solution is simple. Go to your .htaccess fine and find the line that says

RewriteEngine on

If you want to have www part:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

If you don’t want to have www part:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]

Btw. This is applicable and good to be set to every site, not just Magento ones. 🙂