Post #354,723
2/25/12 8:34:47 PM
2/25/12 10:39:59 PM
|
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
Edited by boxley
Feb. 25, 2012, 10:38:33 PM EST
apache mod_rewrite question
is it possible to do substring rewrites on query strings?
example
http://foobar.com/re...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 [R=301,QSA.NC,L]
gives me http://foobar.com/re...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
Edited by boxley
Feb. 25, 2012, 10:39:59 PM EST
|
Post #354,726
2/25/12 11:43:52 PM
|
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.
|
Post #354,727
2/26/12 1:14:14 AM
|
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
|
Post #354,765
2/27/12 4:52:40 PM
|
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.)
|
Post #354,821
2/28/12 4:35:41 PM
|
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
|
Post #354,728
2/26/12 3:57:53 AM
|
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.
|
Post #354,729
2/26/12 8:16:48 AM
|
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
|
Post #354,730
2/26/12 9:22:35 AM
|
Hey, Scott ...
Bet you can't do a shapes example in mod_rewrite.
--
Drew
|
Post #354,731
2/26/12 11:16:42 AM
|
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
|