Remove Session IDs (SID) From URL In Magento

If you’re having problems with Google and other search engines indexing the pages of your Magento Commerce site with session id’s or SID’s, (they look something like this, note the bold SID: http://www.yourdomain.com/service-truck-hardware/d-ring handles.html?SID=ck5gk65tbs0jeml5ebb9flvk27&limit=9&order=manufacturer&dir=asc), here’s the way we fixed it. You may have to try one method or the other. One way worked on one of our websites, the other way worked on the other.

In your .htaccess file, you can try this code:

## remove SID from get request query string
RewriteCond %{request_method} ^GET$
RewriteCond %{QUERY_STRING} ^(.+&)?SID=[\w]*&(.+)?$ [NC]
RewriteRule
^(.*)$ /$1?%1%2 [R=301,L,NE]

and if that doesn’t work, try this code:

## remove SID from get request query string
RewriteCond %{request_method} ^GET$
RewriteCond %{QUERY_STRING} ^((.+)&)?SID=[\w]*$ [NC]
RewriteRule
^(.*)$ /$1?%2 [R=301,L,NE]

Hope that helps!