Solved

Mod Rewrite rules to remove session id

Posted on 2006-11-07
8
2,702 Views
Last Modified: 2008-01-16
Hi everyone, I'm having a difficult time stripping out session id's from our urls.  We no longer generate session ID's in the url, however we have a lot of links out there with them still in the url.  We need to strip them for those people coming in so that google no longer hates us.

Here is a typical URL:  http://www.domain.com/home/contact_us.jsp;jsessionid=cThW1ZRbzXZ4

I need to rewrite that so that it goes instead to: http://www.domain.com/home/contact_us.jsp

And unfortunately, it is not for this single page, but rather for every page we host.. therefor we need a wildcard match for ANY page with sessionid to send them to the correct page.

We are using Apache 1.3.37 on Fedora.

Thanks!
0
Comment
Question by:nstephens
8 Comments
 
LVL 4

Expert Comment

by:Tol_cv
ID: 17896900
try :

RewriteEngine on
RewriteRule ^(.*);jsessionid=(.*)$    $1 [L]
0
 
LVL 16

Expert Comment

by:HackneyCab
ID: 17899497
Is that meant to be a semicolon? I thought query strings had to begin with a question mark? According to the definition of a URI, that is.
0
 

Author Comment

by:nstephens
ID: 17900282
Yes it is meant to be a semilcolon.  It is how the resin java server works by default, I suppose.

Tol_cv, I have tried your rule in the following methods, but to no avail.  the page still comes up with the jsessionid shown.  My understanding is that [L] means "this is the last rule", so I tried it a few different ways, as shown below:

        RewriteEngine on
        RewriteRule ^(.*);jsessionid=(.*)$ $1 [L]
        RewriteOptions inherit

        RewriteEngine on
        RewriteRule ^(.*);jsessionid=(.*)$ $1 [L,PT]
        RewriteOptions inherit

        RewriteEngine on
        RewriteRule ^(.*);jsessionid=(.*)$ $1 [PT]
        RewriteOptions inherit
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 27

Expert Comment

by:caterham_www
ID: 17951491
> the page still comes up with the jsessionid shown

Your rule will rewrite an incomming request of foo;jsessionid=bar to foo, but this will not change the browser's address bar. You must use the R flag In order to change it, and provide an URL-path in the substitution (in directory context your $1 subst. would result in an local filepath without the RewriteBase directive)

The PT flag is only relevant in per-server context (httpd.conf, outside of <directory> sections) for internal rewriting, but anyway I don't know where (=in which context) you're using the rules.

RewriteEngine on
# we do not expect an other ';' in the pattern
RewriteRule ^/([^;]+);jsessionid /$1 [R=301,L]

in order to get this working in directory context (e.g. .htaccess files), remove the leading slash in the rule-pattern (->  ^([^;]+);jsessionid  )
0
 

Author Comment

by:nstephens
ID: 17951553
I attempted your suggestion, but it also failed to work.. my httpd.conf entry looks like such:

        RewriteEngine on
        RewriteRule ^/([^;]+);jsessionid /$1 [R=301,L]
        RewriteOptions inherit

Perhaps this is because the url looks like http://www.domain.com/home/contact_us.jsp;jsessionid=cThW1ZRbzXZ4 (with =[characters]) ?

I don't suppose theres any good log functionality that allows you to see how/when rewrite rules are being used?
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
ID: 17954653
That should match. It doesn't matter what comes right to jsessionid, because the RegEx is left open to the right side and would match anything.

You can track the rewriting process with a RewriteLog, using the directives rewriteLog and RewriteLoglevel, e.g.

Rewritelog logs/rewrite.txt
Rewriteloglevel 5
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question