Solved

Mod Rewrite rules to remove session id

Posted on 2006-11-07
8
2,640 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Fonts cannot be displayed with Firefox and Internet Explorer 6 265
Redirect from old domain to new domain 19 73
Ubuntu 14 with Apache 7 75
PHP in Apache server 20 95
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…
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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