How to remove the SID from magento URLs programatically

Posted June 26th, 2015 in Computers
This page contains snippets of information that may help you to configure Magento to suit your needs.

Remove SID from Magento URLs

Magento will append a SID (session ID) to URLs if the url does not match what is set in admin. Thus, if you access the site without the WWW when the Magento config stipulates that WWW is used, you will see this SID.

Mod rewrite can be used to redirect all non-www traffic to the www version - however, you may find this does not work for you. If this is the case, you can over-ride the file which appends the SID to the link. This is a safe way of making changes to Magento, whereby future upgrades will not break this change.

To stop Magento from appending the SID to urls, build the following directory structure under your Magento install:

app/code/local/Mage/Core/Model/Session

Copy the following file into the Session directory created in the previous step:

app/code/core/Mage/Core/Model/Session/Abstract.php

Open the Abstract.php file and locate the following code:

public function getSessionIdForHost($urlHost)
{
if ($this->getSkipSessionIdFlag() === true) {
return '';
}


Change this code to:

public function getSessionIdForHost($urlHost)
{
return '';
if ($this->getSkipSessionIdFlag() === true) {
return '';
}

This change returns before any checking between www and non-www version of the URL, thus the SID does not get appended.
 

Comments

No comments

Leave a comment