Forum Moderators: phranque

Message Too Old, No Replies

^(redux)(.*)$ $`nauseum$2

Strip 1 query param from an url.

         

cameraman

11:55 pm on Feb 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to strip session id from url so SEs will be happier, since we want our SEs to be happy. So I have this:
http://www.example.com/page.php?needthis=yes&sid=dropit
and this:
http://www.example.com/page.php?sid=dropit

and want to drop the sid in each case (while retaining the possibility of other query parameters as in the first case).

I've actually got it working with ereg_replace:
ereg_replace("((\&joe)=([a-zA-Z0-9]))",'',"www.a.com?b=6&joe=7&c=9")

but I just can't seem to get it to work in .htaccess. I'm checking for my IP address only so that [hopefully] my website will stay up for everyone else. The line will be replaced by conditions looking for bots in the agent.

RewriteCond %{REMOTE_ADDR} ^my.ip.address$
RewriteCond %{QUERY_STRING} ^(^&)(joe)=([a-zA-Z0-9])(.*)$
RewriteRule ^.*$? [C]
RewriteRule ^.*$?%1%4 [R=301]

At this point I'm not even bothering with the second case, I'm just trying to get the first one to work. I've just started using the second RewriteCond on the last 17 iterations because if I'm reading the docs right the query string doesn't get presented in the RewriteRule directive. Before that I was trying to do it with one Cond (the ip exclusion) and one Rule (variations of the last one up there with $1 etc. instead of %1 etc). I'm not seeing any change in the url in my browser.

I've been over the stuff in the library, and I've been over and over the apache docs. While the apache docs finally stopped giving me a raging headache, this stuff just doesn't seem to be penetrating my skull...

I'm pretty sure I can just take care of the whole thing in my php scripts, but it's irking the heck out of me that I can't get this to work.

[edited by: jdMorgan at 2:30 pm (utc) on Feb. 19, 2007]
[edit reason] Disabled smilies in code. [/edit]

jdMorgan

2:43 pm on Feb 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about something like this:

RewriteCond %{REMOTE_ADDR} ^my\.ip\.add\.ress$
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)sid=[^&]*(&([^&]*&)*)?$
RewriteRule (.*) http://example.com/$1?%1%3 [R=301,L]

[^&]*& == "any number of characters not equal to an ampersand, followed by an ampersand."
([^&]*&)* == "As many of the above sequence as you like."
(([^&]*&)*) == And pack them all into %1 for easy back-reference.

Jim

cameraman

7:17 pm on Feb 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Awesome, that of course worked. Thank you very much for the breakdown.

oops, I wasn't escaping the periods in my address, so I expect my site was up & down for everyone..