Forum Moderators: coopster

Message Too Old, No Replies

Hide PHPSESSID : A consolidated solution

PHPSESSID , php session, php.ini settings SEO, restrict content duplication

         

miltan

8:36 am on Apr 30, 2009 (gmt 0)

10+ Year Member



We often face a problem, like having PHPSESSID value in the URL automatically appended. This prevents the user from bookmarking the page and the Search Engine Bots to correctly index the page, and thus reducing the number of visitor and SEO ranking.

example : http://example.com/index.php?PHPSESSID=65e9cc7bf996...

To avoid this we have the following ways

1. If the web server uses apache handler, and the php config settings are manageable thru' .htaccess file:

simply add the following lines to your .htaccess file

php_value session.use_only_cookies 1
php_value session.use_trans_sid 0

2. Alternatively, if your web server uses CGI handler, and the php config settings are overridden only by local php.ini files, then create a local copy of php.ini file in the required directory and add modify the following directives as:

session.use_only_cookies = 1
session.use_trans_sid = 0

3. If permitted, you can also modify the php.ini settings from within the page using the following code snippet

ini_set('session.use_trans_sid', false);
ini_set('session.use_only_cookies', true);

Regards
Miltan

coopster

12:04 pm on Apr 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, miltan, and thanks for the reminder. Anybody wishing to know more about sessions and SID should read through the PHP manual pages regarding Sessions [php.net]. A must read IMHO.

g1smd

9:19 pm on Apr 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you already have URLs with sessions indexed, and the URLs do not use any other parameters, this code placed in the root .htaccess file of an Apache server can start to fix the issue:

RewriteCond %{QUERY_STRING} [b]&?[/b]sessionid=([^&]+)[b]&?[/b] [NC]
RewriteRule (.*) http://www.example.com/$1? [R=301,L]