How to disable PHPSESSID from URL

This is a quick howto disable PHPSESSID form appearing in your url an messing upp your google search results. The background to the problem is that googlebot doesnt use cookies and therefore will apache store the PHPSESSID in the url instead. To fix this, create a file called .htaccess and put in in you webroot. (note the dot before the filename)

The file must have the following contents:


#Force PHPSESSID into cookie or not bother
php_value session.use_only_cookies 1
php_value session.use_trans_sid    0

<IfModule mod_rewrite.c>
  RewriteEngine on
  Options All

  #Remove PHPSESSID from existing links to your webpage.
  #This tells google that your page /index.php?foo=bar&PHPSESSID=dasdagas has 
  #moved to /index.php?foo=bar
  RewriteCond %{QUERY_STRING} PHPSESSID=.*$ 
  RewriteRule .* %{REQUEST_URI}? [R=301,L]
</IfModule>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <strong> <cite> <code> <b> <i>
  • Lines and paragraphs break automatically.

More information about formatting options