Using mod_rewrite to modify Query String
Using mod_rewrite to modify Query String
am 24.10.2007 21:49:05 von Laura
Dear all,
I have to the need to modify the query string so that when a parameter
is assigned the string value "null" it should eliminated from the
query string or also it's ok if it's assigned to a no value
for example:
http://server/cgi?param1=null¶m2=dummy
should be translated to:
http://server/cgi?param2=dummy
or if this is not possible to:
http://server/cgi?param1=¶m2=dummy
Any help ?
Thanks
Laura
Re: Using mod_rewrite to modify Query String
am 25.10.2007 01:10:50 von shimmyshack
On Oct 24, 8:49 pm, Laura wrote:
> Dear all,
> I have to the need to modify the query string so that when a parameter
> is assigned the string value "null" it should eliminated from the
> query string or also it's ok if it's assigned to a no value
>
> for example:
>
> http://server/cgi?param1=null¶m2=dummy
>
> should be translated to:
>
> http://server/cgi?param2=dummy
>
> or if this is not possible to:
>
> http://server/cgi?param1=¶m2=dummy
>
> Any help ?
> Thanks
> Laura
hi Laura, your question was answered some moments ago on this group,
kind of
http://groups.google.com/group/alt.apache.configuration/brow se_thread/thread/f44d0b0c365b90bd
RewriteCond %{QUERY_STRING} wxyz
RewriteRule (.*)
but of course you would have
RewriteEngine On
RewriteCond %{QUERY_STRING} ^&?param1=null&(.*) [OR]
RewriteCond %{QUERY_STRING} ^(.*)¶m1=null&?$ [OR]
RewriteCond %{QUERY_STRING} ^(.*)¶m1=null&(.*)
RewriteRule . %{REQUEST_URI}?%1&%2 [L]
is there a reason why you dont want to handle this in the application
layer itself?
messy, which is why i would do it in the app layer!!
Re: Using mod_rewrite to modify Query String
am 25.10.2007 08:28:00 von Laura
On 25 Ott, 01:10, shimmyshack wrote:
> On Oct 24, 8:49 pm, Laura wrote:
>
>
>
>
>
> > Dear all,
> > I have to the need to modify the query string so that when a parameter
> > is assigned the string value "null" it should eliminated from the
> > query string or also it's ok if it's assigned to a no value
>
> > for example:
>
> >http://server/cgi?param1=3Dnull=B6m2=3Ddummy
>
> > should be translated to:
>
> >http://server/cgi?param2=3Ddummy
>
> > or if this is not possible to:
>
> >http://server/cgi?param1=¶m2=3Ddummy
>
> > Any help ?
> > Thanks
> > Laura
>
> hi Laura, your question was answered some moments ago on this group,
> kind of
>
> http://groups.google.com/group/alt.apache.configuration/brow se_thread...
>
> RewriteCond %{QUERY_STRING} wxyz
> RewriteRule (.*)
>
> but of course you would have
>
> RewriteEngine On
> RewriteCond %{QUERY_STRING} ^&?param1=3Dnull&(.*) [OR]
> RewriteCond %{QUERY_STRING} ^(.*)¶m1=3Dnull&?$ [OR]
> RewriteCond %{QUERY_STRING} ^(.*)¶m1=3Dnull&(.*)
> RewriteRule . %{REQUEST_URI}?%1&%2 [L]
>
>
> is there a reason why you dont want to handle this in the application
> layer itself?
>
> messy, which is why i would do it in the app layer!!- Nascondi testo tra =
virgolette -
>
> - Mostra testo tra virgolette -
Hello, thanks a lot for your answer, sorry I missed the post you
mentioned....
> is there a reason why you dont want to handle this in the application
> layer itself?
The problem is that, we have an apache module called mod_plsql which
forwards
the path /oracle/PROCNAME to the Oracle Stored PROCNAME.
We discovered that when a parameter is null, the query string builds
up like
/oracle/PROCNAME?param1=3Dnull
and the Stored Procedure underestands that VARCHAR "null" is passes
instead of a
null parameter
So the choice is:
-either "clean" from JavaScript all query string
-or insert into Oracle Stored procedure a check: if ( param1 =3D
'null' )
but this would be a huge effort because we have about 300 web pages
and about the same
stored procedures...........
so I thought Apache could save us..........
by the way: since there can be more parameters with "null" in the
query string, do you think
that would work the same ?
Thanks a lot for your help!
Laura
Re: Using mod_rewrite to modify Query String
am 25.10.2007 09:34:25 von Laura
On 25 Ott, 08:28, Laura wrote:
> On 25 Ott, 01:10, shimmyshack wrote:
>
>
>
>
>
> > On Oct 24, 8:49 pm, Laura wrote:
>
> > > Dear all,
> > > I have to the need to modify the query string so that when a parameter
> > > is assigned the string value "null" it should eliminated from the
> > > query string or also it's ok if it's assigned to a no value
>
> > > for example:
>
> > >http://server/cgi?param1=3Dnull=B6m2=3Ddummy
>
> > > should be translated to:
>
> > >http://server/cgi?param2=3Ddummy
>
> > > or if this is not possible to:
>
> > >http://server/cgi?param1=¶m2=3Ddummy
>
> > > Any help ?
> > > Thanks
> > > Laura
>
> > hi Laura, your question was answered some moments ago on this group,
> > kind of
>
> >http://groups.google.com/group/alt.apache.configuration/bro wse_thread...
>
> > RewriteCond %{QUERY_STRING} wxyz
> > RewriteRule (.*)
>
> > but of course you would have
> >
> > RewriteEngine On
> > RewriteCond %{QUERY_STRING} ^&?param1=3Dnull&(.*) [OR]
> > RewriteCond %{QUERY_STRING} ^(.*)¶m1=3Dnull&?$ [OR]
> > RewriteCond %{QUERY_STRING} ^(.*)¶m1=3Dnull&(.*)
> > RewriteRule . %{REQUEST_URI}?%1&%2 [L]
> >
>
> > is there a reason why you dont want to handle this in the application
> > layer itself?
>
> > messy, which is why i would do it in the app layer!!- Nascondi testo tr=
a virgolette -
>
> > - Mostra testo tra virgolette -
>
> Hello, thanks a lot for your answer, sorry I missed the post you
> mentioned....
>
> > is there a reason why you dont want to handle this in the application
> > layer itself?
>
> The problem is that, we have an apache module called mod_plsql which
> forwards
> the path /oracle/PROCNAME to the Oracle Stored PROCNAME.
> We discovered that when a parameter is null, the query string builds
> up like
>
> /oracle/PROCNAME?param1=3Dnull
>
> and the Stored Procedure underestands that VARCHAR "null" is passes
> instead of a
> null parameter
>
> So the choice is:
> -either "clean" from JavaScript all query string
> -or insert into Oracle Stored procedure a check: if ( param1 =3D
> 'null' )
>
> but this would be a huge effort because we have about 300 web pages
> and about the same
> stored procedures...........
>
> so I thought Apache could save us..........
>
> by the way: since there can be more parameters with "null" in the
> query string, do you think
> that would work the same ?
> Thanks a lot for your help!
> Laura- Nascondi testo tra virgolette -
>
> - Mostra testo tra virgolette -
well I have tried, with one parameter it works...but there can be many
"null" parameters as well.....and the number of parameters if
different in every page.........
My problem is to write a "RewriteRule" for an unknown number of
parameters.......
What a mess !!
I hope somebody is able to code this RewriteRule.....
Thanks again
Laura
Re: Using mod_rewrite to modify Query String
am 25.10.2007 16:07:10 von HansH
"Laura" schreef in bericht
news:1193297665.501687.146640@v23g2000prn.googlegroups.com.. .
> > is there a reason why you dont want to handle this in the application
> > layer itself?
>
> The problem is that, we have an apache module called mod_plsql which
> forwards the path /oracle/PROCNAME to the Oracle Stored PROCNAME.
> We discovered that when a parameter is null, the query string builds
> up like
> /oracle/PROCNAME?param1=null
> and the Stored Procedure underestands that VARCHAR "null" is passes
> instead of a null parameter
At some point(s) Oracle can not distinct between a zero length string and
NULL.
This might be why mod_plsql HAS TO DO this dirty tric ...
> So the choice is:
> -either "clean" from JavaScript all query string
> -or insert into Oracle Stored procedure a check: if ( param1 = 'null' )
>
> but this would be a huge effort because we have about 300 web pages
> and about the same stored procedures...........
>
> so I thought Apache could save us..........
>
> by the way: since there can be more parameters with "null" in the
> query string, do you think that would work the same ?
Try
RewriteEngine On
RewriteCond %{QUERY_STRING} (.*)=null(&.*)?$
RewriteRule . %{REQUEST_URI}?%1=%2 [N]
It should do Next rounds while '=null' is found, thus trimming the value off
of any randomly named parameter one at a time.
From your initial post I interpreted the problem being '_mod_plsql_ is
inserting a reserved value', which is then beyond the reach of any rewrite.
I do hope the null is part of the request the browser sends to Apache.
Be aware Rewrites can NOT handle POSTed forms, which might bring you back
to
- insert into Oracle Stored procedure a check: if ( param1 = 'null' )
HansH
Re: Using mod_rewrite to modify Query String
am 25.10.2007 19:27:10 von Jim Hayter
Laura wrote:
> by the way: since there can be more parameters with "null" in the
> query string, do you think
> that would work the same ?
> Thanks a lot for your help!
> Laura
You might consider using the RewriteMap directive to send your
Query_string to a script to parse and rewrite. You could then use the
result as either an internal or external redirect.
Example (untested):
RewriteMap fix_query_string prg:
RewriteCond %{QueryString} "=null"
RewriteCond %{QueryString} ^(.+)$
RewriteRule ^(.*)$ $1?${fix_query_string:%1|%1}
The first condition tests for the "=null" string, the second puts the
query string in %1. The rewrite rule captures the request_uri in $1 and
rewrites it to itself with the result of passing the query string to the
script. If the script returns the special value "NULL", it uses the
final %1 (after the |) instead of the script output. You will probably
need to consult a good source on how to write the script. It is started
when Apache starts and reads from stdin and writes to stdout.
HTH,
Jim
Re: Using mod_rewrite to modify Query String
am 25.10.2007 19:33:33 von HansH
"Jim Hayter" schreef in bericht
news:13i1kffdhhmfm06@news.supernews.com...
> Laura wrote:
>
>> by the way: since there can be more parameters with "null" in the
>> query string, do you think that would work the same ?
>
> You might consider using the RewriteMap directive to send your
> Query_string to a script to parse and rewrite. You could then use the
> result as either an internal or external redirect.
>
> Example (untested):
> RewriteMap fix_query_string prg:
> RewriteCond %{QueryString} "=null"
> RewriteCond %{QueryString} ^(.+)$
> RewriteRule ^(.*)$ $1?${fix_query_string:%1|%1}
>
> The first condition tests for the "=null" string, the second puts the
> query string in %1. The rewrite rule captures the request_uri in $1 and
> rewrites it to itself with the result of passing the query string to the
> script. If the script returns the special value "NULL", it uses the final
> %1 (after the |) instead of the script output. You will probably need to
> consult a good source on how to write the script. It is started when
> Apache starts and reads from stdin and writes to stdout.
>
Maps do not only eat backticks:
RewriteMap fix_query_string prg:
RewriteCond %{QueryString} "=null"
RewriteRule ^(.*)$
$1?${fix_query_string:%{QueryString}|%{QueryString}}
HansH
Re: Using mod_rewrite to modify Query String
am 25.10.2007 20:34:33 von Jim Hayter
HansH wrote:
> "Jim Hayter" schreef in bericht
> news:13i1kffdhhmfm06@news.supernews.com...
> Maps do not only eat backticks:
> RewriteMap fix_query_string prg:
> RewriteCond %{QueryString} "=null"
> RewriteRule ^(.*)$
> $1?${fix_query_string:%{QueryString}|%{QueryString}}
>
Thanks. I was not aware of that.
Jim