Some may notice when perusing a Magento install that the following appears at the end of a given URL: http://magento/?SID=randomtext. Pretty unattractive and it discounts Search Engine ratings given that you’re making it obvious that your Magento store utilizes dynamic URLs rather than the preferred static variety.

The Problem

Magento support explains the purpose of the session ID like this:

The session ID is transfered in URL whenever there’s a change in the host name, so the session would be transfered to the next page.  Usually session ID is kept in the cookie, but cookies can’t be shared between different domains, so it has to be transferred in URL. This is Magento’s functionality, not PHP, so changing PHP configuration will not help.  Note, that SID will be added to URL only the first time new domain is encountered during the session.

Knowing this, we can discern that the problem arises whenever a user moves between the two host names found on a given domain.  These are the ‘www’ and ‘non-www’ versions.  Most search engines will see these as two different sites and index them as such, but with Magento, an admin can only select one of these as the ‘base_url’ and populate that portion. When a user moves from the ‘base_url’ to lets say, the ‘www’ version, a session id is created to move the data from the base_url session to the new one and thus creates a dynamic URL.

The Workaround

There are two ways to work around this. The first is to modify the php.ini file found in your magento root folder.

session.use_trans_sid = 0

Using this code will remove all SIDs from the http: version of your site, but will break down when one moves to the https:.  I’m not sure why this is, it probably has to do with moving to a different port or initializing the SSL certificate but in short, this will work though it isn’t the best option. Option 2 will remove the SIDs from being created but will also limit the scope of the search engines indexing to the host name of your choice, which can, in theory, give your domain more page rank and power.

Despite this being about magento, the first step is important for any website being created; one must decide what version of the domain they would like to present to the search engines.  For this domain, I chose to use the ‘non-www’ version of the site and have stuck with that. You may choose differently so I’ve included both below.  Open your .htaccess and look for the line

RewriteEngine on

Include one of the following versions depending on how you would like your magento store or website to display.

For the ‘www’ version:

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

For the ‘non-www’ version:

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

Minneapolis Magento Web Development

Do you need a Magento developer for your ecommerce store? Snap Agency is a Minneapolis online marketing agency that specializes in web development services for ecommerce stores based on the Magento platform. Give us a call at (763) 548-2297 or email us to request a free consultation.