Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite - QUERY STRING is matching - but where to go from here?

need help dismantling & reassembling querystring

         

circuitspore

3:42 am on Sep 12, 2006 (gmt 0)

10+ Year Member



I'm a mod_rewrite noob, so have mercy...........

There are URLs hanging around like:
http://www.example.com/sim/jsp/commerce_order_history.do?mode=orderHistory
&BV_SessionID=@@@@1335499620.1157821238@@@@&BV_EngineID=ccddaddikkleefdcflgcefkdfkjdffl.0&channelId=-8815
&rootChannelName=%2FCommerce+Navigation%2FCustomer+Service&channelName=Customer+Service&programId=1610630353

I want to strip out the BV_SessionID and BV_EngineID variables and 301 redirect to a 'session-free' URL like:
http://www.example.com/sim/jsp/commerce_order_history.do?mode=orderHistory&channelId=-8815
&rootChannelName=%2FCommerce+Navigation%2FCustomer+Service&channelName=Customer+Service&programId=1610630353

Note: This is just a single example, throughout the site there are many different filenames with various querystrings, the only thing they ALL have in common is the fact that they contain the BV_SessionID and BV_EngineID variables. So I'm trying to write a rule that captures any URL containing the session/engine variables in the querystring.

I have the following rule that I've been tinkering with:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)&BV_SessionID=(.*)&BV_EngineID=(.*)\.[0-9]*(.*)
RewriteRule (.*)? http://www.example.com/test.htm? [R=301,L]

I know that I've got the QUERY_STRING condition matching because the first URL mentioned above 301 redirects to /test.htm.

But I'm not sure where to go from here. I'm not sure how to write the RewriteRule so that is pulls the different pieces of the regular expression apart and then rewrites the URL to just include what (I think) should be "$1" and "$4" from the expression.

Any help? Am I even making sense? %-)

[edited by: jdMorgan at 2:23 pm (utc) on Sep. 12, 2006]
[edit reason] Fix side-scroll, examplified [/edit]

circuitspore

1:34 pm on Sep 12, 2006 (gmt 0)

10+ Year Member



update:

i've written this rule, which I _thought_ would work, but doesn't:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)&BV_SessionID=(.*)&BV_EngineID=(.*)\.[0-9]*(.*)
RewriteRule ^/(.*)\?(.*)&BV_SessionID=(.*)&BV_EngineID=(.*)\.[0-9]*(.*)$ /$1\?$2$5 [R=301,L]

anyone?

jdMorgan

2:22 pm on Sep 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your first rule was closer, but you'll need to use %1 and %4, not $1 and $4, to refer to variables matched into RewriteCond patterns.

Jim