Using mod_rewrite to modify Query String

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
Laura [ Mi, 24 Oktober 2007 21:49 ] [ ID #1853387 ]

Re: Using mod_rewrite to modify Query String

On Oct 24, 8:49 pm, Laura <f.marchi... [at] pride.it> 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 (.*) <redirect URL>

but of course you would have
<Directory "htdocs/vhosts/test/public/rewrites">
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]
</Directory>

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!!
shimmyshack [ Do, 25 Oktober 2007 01:10 ] [ ID #1854358 ]

Re: Using mod_rewrite to modify Query String

On 25 Ott, 01:10, shimmyshack <matt.fa... [at] gmail.com> wrote:
> On Oct 24, 8:49 pm, Laura <f.marchi... [at] pride.it> 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=3D=B6m2=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 (.*) <redirect URL>
>
> but of course you would have
> <Directory "htdocs/vhosts/test/public/rewrites">
> 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]
> </Directory>
>
> 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
Laura [ Do, 25 Oktober 2007 08:28 ] [ ID #1854363 ]

Re: Using mod_rewrite to modify Query String

On 25 Ott, 08:28, Laura <f.marchi... [at] pride.it> wrote:
> On 25 Ott, 01:10, shimmyshack <matt.fa... [at] gmail.com> wrote:
>
>
>
>
>
> > On Oct 24, 8:49 pm, Laura <f.marchi... [at] pride.it> 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=3D=B6m2=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 (.*) <redirect URL>
>
> > but of course you would have
> > <Directory "htdocs/vhosts/test/public/rewrites">
> > 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]
> > </Directory>
>
> > 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
Laura [ Do, 25 Oktober 2007 09:34 ] [ ID #1854364 ]

Re: Using mod_rewrite to modify Query String

"Laura" <f.marchioni [at] pride.it> schreef in bericht
news:1193297665.501687.146640 [at] 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
HansH [ Do, 25 Oktober 2007 16:07 ] [ ID #1854366 ]

Re: Using mod_rewrite to modify Query String

Laura wrote:
<snip>
> 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:<location of program>
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
Jim Hayter [ Do, 25 Oktober 2007 19:27 ] [ ID #1854370 ]

Re: Using mod_rewrite to modify Query String

"Jim Hayter" <see.reply.to [at] nowhere.invalid> schreef in bericht
news:13i1kffdhhmfm06 [at] news.supernews.com...
> Laura wrote:
> <snip>
>> 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:<location of program>
> 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:<location of program>
RewriteCond %{QueryString} "=null"
RewriteRule ^(.*)$
$1?${fix_query_string:%{QueryString}|%{QueryString}}

HansH
HansH [ Do, 25 Oktober 2007 19:33 ] [ ID #1854371 ]

Re: Using mod_rewrite to modify Query String

HansH wrote:
> "Jim Hayter" <see.reply.to [at] nowhere.invalid> schreef in bericht
> news:13i1kffdhhmfm06 [at] news.supernews.com...

<snip my suggestion>

> Maps do not only eat backticks:
> RewriteMap fix_query_string prg:<location of program>
> RewriteCond %{QueryString} "=null"
> RewriteRule ^(.*)$
> $1?${fix_query_string:%{QueryString}|%{QueryString}}
>

Thanks. I was not aware of that.

Jim
Jim Hayter [ Do, 25 Oktober 2007 20:34 ] [ ID #1854372 ]
Webserver » alt.apache.configuration » Using mod_rewrite to modify Query String

Vorheriges Thema: GET a page from another address?
Nächstes Thema: force https off if a subdomain