IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New apache mod_rewrite question
is it possible to do substring rewrites on query strings?
appears that url shortening is foobaring the examples, I will put a couple of white spaces in
example
http://foobar.com/ redirect?1=one&2=two&3=three

I want to keep the string intact except change 1=one to 1=five

if I do this
RewriteCondition *.1=one
ReWriteRule ^/redirect(.) http://foobar.com/redirect?1=five$1 [P,QSA.NC,L]
gives me http://foobar.com/ redirect?1=five&1=one&2=two&3=three

I can replace the entire string but at work but it is 30 fields in length and variable so there is no real way to do it

My solution is to tell the developers that's what Java is for

Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free American and do not reflect the opinions of any person or company that I have had professional relations with in the past 55 years. meep
Expand Edited by boxley Feb. 25, 2012, 10:38:33 PM EST
Expand Edited by boxley Feb. 25, 2012, 10:39:59 PM EST
New Do you really need the QSA?
From the mod_rewrite docs:
qsappend|QSA' (query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it.
That looks like setting up for trouble in this case.

(.) matches a single character (the question mark) and should result in http://foobar.com/ redirect?1=five?1=one&2=two

Try RewriteRule (.*)1=one(.*) http://foobar.com/$11=five$2 [P,NC,L]

Other than that, I'm not sure if the condition rule triggers: it should be "RewriteCond", and one of the parameters is missing.
New tried that
everything after the ? is ignored.

will play around tomorrow
apparently this is a highly visible issue
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free American and do not reflect the opinions of any person or company that I have had professional relations with in the past 55 years. meep
New It is possible...
The key is to use the RewriteCond and then use the % backrefs:

RewriteCond %{QUERY_STRING} (.*)1=one(.*)
RewriteRule index.html redirect.html?%11=five%2 [L]


(URL and host names don't match your example, but this is what I got working on my server. The rest shouldn't be to hard to reconstruct.)
New thanx, turns out the rewrite doesnt help as the app
mangles the query string in any case
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free American and do not reflect the opinions of any person or company that I have had professional relations with in the past 55 years. meep
New I'd be moving it out of the rewrite.
IMO, mod_rewrite is a solution for when it's clearly not the application's problem. I've seen unmaintainable messes of rewrite rules and have no wish to encourage that in the apps I support. :-(

Trouble is, this decision is rarely cut-n-dried. I would be trying to push it into the application, even as you're trying for a mod_rewrite solution. All Java frameworks have hooks to hang classes to sort this out, if they can't or won't fix it in the controlllers or actions. Maybe encourage the devs to think of it as a competition. :-)

Wade.
Just Add Story http://justaddstory.wordpress.com/
New ed zachery
as it is my httpd.conf has 11k+ lines of rewrites
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free American and do not reflect the opinions of any person or company that I have had professional relations with in the past 55 years. meep
New Hey, Scott ...
Bet you can't do a shapes example in mod_rewrite.
--

Drew
New its easy enuff
if you rewrite the query string in it entirety. It appears that substring manipulations are out of bounds, although I havn't looked at the mod_rewrite source code yet.
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free American and do not reflect the opinions of any person or company that I have had professional relations with in the past 55 years. meep
     apache mod_rewrite question - (boxley) - (8)
         Do you really need the QSA? - (scoenye) - (3)
             tried that - (boxley) - (2)
                 It is possible... - (scoenye) - (1)
                     thanx, turns out the rewrite doesnt help as the app - (boxley)
         I'd be moving it out of the rewrite. - (static) - (3)
             ed zachery - (boxley) - (2)
                 Hey, Scott ... - (drook) - (1)
                     its easy enuff - (boxley)

Yeah, let's watch the lamp. It's more fun and less predictable.
87 ms