Forum Moderators: phranque
Am relatively new to mod_rewrite and am trying to rewrite one of our dynamic pages query strings to make it indexable. I'm having problems with the JSessionID our weblogic server attaches to the query string if cookies are disabled. I want it to change from JSESSIONID=DhF6hLz3G82XNw0r5qVHzfhqJ5QfYp87hVvb7v7j05gyBF9G!-1734146260
to something like:
/DhF6hLz3G82XNw0r5qVHzfhqJ5QfYp87hVvb7v7j05gyBF9G/1734146260
This is what I have for my rewrite rule:
RewriteCond %{QUERY_STRING} ^.*JSESSIONID=.*$
RewriteRule ^(.*)JESSSIONID=([A-Za-z0]+)([!-]*)([0-9]+)(.*)$ /JSESSIONID/$1/$3 [R,L]
But it doesn't seem to be applying it. Any help would be much appreciated.
Thanks Alex
Welcome to WebmasterWorld!
The query string cannot be 'seen' or accessed by RewriteRule. If you need back-references, create them in RewriteCond and access them using %1 through %9 in the subsequent RewriteRule, in a similar way to the use of $1 through $9 backreferences created by the RewriteRule pattern.
RewriteCond %{QUERY_STRING} ^(.*)JESSSIONID=([a-z0]+)([!-]*)([0-9]+)(.*)$ [NC]
RewriteRule .* http://www.example.com/JSESSIONID/%1/%3? [R=301,L]
I should also note that if your purpose here is to create search-engine friendly URLs, then you may be going about this backwards; The usual technique is to modify your scripts to output SE-friendly static links on your pages, and then use mod_rewrite to convert those URLs, when requested from your server, back into the dynamic form needed to invoke your script and generate another page.
If your purpose is to remove dynamic URLs from search engine listings, then that requires a different approach. See this recent thread [webmasterworld.com] for more.
For additional information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim