Hiding jsessionid parameter from Google

If you’re running a website on JBoss you may discover that Google has indexed your pages with a jsessionid query parameter in the links.

The Google crawl bot does not support cookies, therefore JBoss uses the jsessionid query parameter in order to maintain a session state without cookies. These query parameters can impact your Google rank and indexing efficiency as the same page can be indexed multiple times with different session ids, and dilute your ranking. Also, it leads to ugly links.

If you want to still be able to support non-cookie using users, but would like Google to see cleaner links, you can use Apache’s mod_rewrite to modify the links for the Google bot only, leaving the normal functionality available to the rest of your users.

Assuming you have mod_rewrite enabled in your Apache instance, use this configuration in your apache config:

[code]
# This should strip out jsessionids from google
RewriteCond %{HTTP_USER_AGENT} (googlebot) [NC]
ReWriteRule ^(.*);jsessionid=[A-Za-z0-9]+(.*)$ $1$2 [L,R=301]
[/code]
This rule says for request where the user agent contains “googlebot” (with case insensitive matching), rewrite the URL without the jsessionid. It seems to work nicely.


Posted

in

by

Comments

3 responses to “Hiding jsessionid parameter from Google”

  1. […] of just using the Apache mod_rewrite rules from my post on “Hiding jsessionid parameters from Google”, which uses redirects, wouldn’t it be better to simply not output the jsessionid parameter into […]

  2. […] posted two solutions to this issue in the past: Using Apache to ReWrite URLs to remove JSESSIONID and a more advanced solution of using a Servlet Filter to avoid adding JSESSIONID for GoogleBot […]

  3. Andrew Avatar
    Andrew

    Thanks for the example for rewriting the urls for Google. We also use it for making sure that the spider we use does not create files with jsessionid in the file names. One thing to be aware of is that the list of valid characters for a JBoss jsession id can include “-“, “+” and “*”. We use the following:

    RewriteCond %{HTTP_USER_AGENT} (AESpider) [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} (googlebot) [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} (MSNBot) [NC]
    RewriteRule ^([^;]+);jsessionid=[A-Za-z0-9\-\+\*]+\.[A-Za-z0-9]+(.*)$ $1$2 [L,R=301]

    Andrew

Leave a Reply

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com