Using mod_rewrite to modify Query String

This is a discussion on Using mod_rewrite to modify Query String within the Apache Web Server forums, part of the Web Server and Related Forums category; Dear all, I have to the need to modify the query string so that when a parameter is assigned the ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-24-2007
Laura
 
Posts: n/a
Default 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&param2=dummy

should be translated to:

http://server/cgi?param2=dummy

or if this is not possible to:

http://server/cgi?param1=&param2=dummy

Any help ?
Thanks
Laura

  #2 (permalink)  
Old 10-25-2007
shimmyshack
 
Posts: n/a
Default Re: Using mod_rewrite to modify Query String

On Oct 24, 8:49 pm, Laura <f.marchi...@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&param2=dummy
>
> should be translated to:
>
> http://server/cgi?param2=dummy
>
> or if this is not possible to:
>
> http://server/cgi?param1=&param2=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.a...4d0b0c365b90bd

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} ^(.*)&param1=null&?$ [OR]
RewriteCond %{QUERY_STRING} ^(.*)&param1=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!!

  #3 (permalink)  
Old 10-25-2007
Laura
 
Posts: n/a
Default Re: Using mod_rewrite to modify Query String

On 25 Ott, 01:10, shimmyshack <matt.fa...@gmail.com> wrote:
> On Oct 24, 8:49 pm, Laura <f.marchi...@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.a.../browse_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=null&(.*) [OR]
> RewriteCond %{QUERY_STRING} ^(.*)&param1=null&?$ [OR]
> RewriteCond %{QUERY_STRING} ^(.*)&param1=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!!- 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=null

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 =
'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


  #4 (permalink)  
Old 10-25-2007
Laura
 
Posts: n/a
Default Re: Using mod_rewrite to modify Query String

On 25 Ott, 08:28, Laura <f.marchi...@pride.it> wrote:
> On 25 Ott, 01:10, shimmyshack <matt.fa...@gmail.com> wrote:
>
>
>
>
>
> > On Oct 24, 8:49 pm, Laura <f.marchi...@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.a.../browse_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=null&(.*) [OR]
> > RewriteCond %{QUERY_STRING} ^(.*)&param1=null&?$ [OR]
> > RewriteCond %{QUERY_STRING} ^(.*)&param1=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!!- 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=null
>
> 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 =
> '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


  #5 (permalink)  
Old 10-25-2007
HansH
 
Posts: n/a
Default Re: Using mod_rewrite to modify Query String

"Laura" <f.marchioni@pride.it> schreef in bericht
news:1193297665.501687.146640@v23g2000prn.googlegr oups.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


  #6 (permalink)  
Old 10-25-2007
Jim Hayter
 
Posts: n/a
Default 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
  #7 (permalink)  
Old 10-25-2007
HansH
 
Posts: n/a
Default Re: Using mod_rewrite to modify Query String

"Jim Hayter" <see.reply.to@nowhere.invalid> schreef in bericht
news:13i1kffdhhmfm06@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




  #8 (permalink)  
Old 10-25-2007
Jim Hayter
 
Posts: n/a
Default Re: Using mod_rewrite to modify Query String

HansH wrote:
> "Jim Hayter" <see.reply.to@nowhere.invalid> schreef in bericht
> news:13i1kffdhhmfm06@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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:47 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0