How to remove magento sid on frontend

What to do to solve SID problem in Magento

Sid Problem
Magento SID problem is caused by Magento itself because Magento use sid on frontend by default; Magento lets PHP's session to start even the user is not logged in and in some configuration, Magento puts the Session ID with the parameter "SID" in url and even as a cookie, so in example, the main url of a website, may become: http://domain.tld/?SID=xxx&yyy

Magento sid on frontend url: what does it is?

The cms Magento in some configuration let php's sessions to start even the user is not logged in and it puts the Session id in the url as a get parameter and even as a cookie.

Speaking in terms of web development the fact that magento use sid on frontend is not a bad thing but speaking in seo terms we have to consider it a real problem

SID parameters in url: why to solve Magento's sid problem?

Search engine optimization, is a subject that usually we call seo and its main purpose is to collect a various tecniques to communicate not just with people but even with search engines that of course are algorithms and that can't use eyes or ears; the goal of every search engines is to give the user the best answer to a question offering him an ordered list of search results that are focused on the topic of the query

Search engines like Google or DuckDuckGo recommends to avoid have duplicate content on the same website because it's better for a user that will visit your website that you take care of your web pages, in person and not just with an automated system.

Magento sid on frontend url is in fact a content duplicate generator, for any kind of our web page stored in our web space, in every moment and may cause the indexing of hundreds different url (with a different SID) of the same page.

magento sid in url

A flow graph representing the traffic of a website made with magento that has thousands versions of the same page stored in google's Serp

Every time the crawler scan a website, the server generate a new php session and magento store the session id sid in url so google intercept a "brand new url" with the same content of the original one, in fact, registering a duplicated content.

Common solutions to remove magento sid in url

Magento and Magento 2 remove sid from url in two different way.

  1. In some configuration Magento 2 let you solve the problem by its admin panel:

    Go to Admin > Store > Web > Session Validation settings.

    magento 2 sid in url
    Magento 2 screen capture to remove sid in url
  2. If magento use sid on frontend the solution above is not always usable due to the configuration of the software, so we can use an alternate ones that works always, in magento 1.9.x and in magento 2 remove sid from url: edit the .htaccess file

Definitive solutions: .htaccess

Just add this lines of code upper you can:

RewriteEngine On
RewriteCond %{THE_REQUEST} \?(.*)SID(.*)\ HTTP/ [NC]
RewriteRule (.*) /$1? [R=301,L]