Welcome! Log In Create A New Profile

Advanced

Re: Redirect on $args based on multiple params?

April 04, 2009 01:54PM
On Thu, Mar 26, 2009 at 01:35:40PM +0300, Maxim Dounin wrote:

> Hello!
>
> On Thu, Mar 26, 2009 at 01:17:36AM +0300, Igor Sysoev wrote:
>
> > On Wed, Mar 25, 2009 at 08:58:00PM +0300, Maxim Dounin wrote:
> >
> > > Hello!
> > >
> > > On Wed, Mar 25, 2009 at 03:55:02PM +0000, Phillip B Oldham wrote:
> > >
> > > > Is there any way to capture multiple parameters from a querystring for a
> > > > rewrite?
> > > >
> > > > For example:
> > > > The request is: /myscript.php?a=b&c=d&z=y
> > > > The target is: /script/a/b/c/d/z/y
> > > >
> > > > So, the basic rewrite would be:
> > > >
> > > > location /myscript.php {
> > > > if( $args ~* ^a=([^\&]+)&b=([^\&]+)&z=([^\&]+)$ ){
> > > > rewrite ^ /script/a/$1/b/$2/z/$3 permanent;
> > >
> > > JFYI: This won't ever pass configuration tests - captures from
> > > if() will be reset by rewrite itself. It should use intermediate
> > > set's to save captures. Also, "if(" should be rewritten as "if (",
> > > and probably trailing '?' should be added to rewrite destination
> > > to avoid query string appending.
> > >
> > > Correct version would be
> > >
> > > location /myscript.php {
> > > if ($args ~* ^a=([^\&]+)&b=([^\&]+)&z=([^\&]+)$) {
> > > set $a $1;
> > > set $b $2;
> > > set $z $3;
> > > rewrite ^ /script/a/$a/b/$b/z/$z? permanent;
> > > }
> > > }
> > >
> > > > }
> > > > }
> > > >
> > > > However, how would I cope with situations where the args aren't in the
> > > > order of a/b/z? Obviously if I have 10 args I don't want to have to do
> > > > an "if" for each permutation, that could get both confusing and lengthy!
> > >
> > > In 0.7.8+ you may use $arg_* variables for this, e.g.
> > >
> > > location /myscript.php {
> > > rewrite ^ /script/a/$arg_a/b/$arg_b/z/$arg_z? permanent;
> > > }
> >
> > I forgot simply about them :)
>
> Sure. :)
>
> And it looks like you also forgot about my patch that fixes them
> when used in ssi subrequests. It still applies cleanly to 0.7.44.
> Should I resend it?

No, it will be in next 0.7.48, thank you.


--
Igor Sysoev
http://sysoev.ru/en/
Subject Author Posted

Redirect on $args based on multiple params?

Phillip B Oldham March 25, 2009 11:55AM

Re: Redirect on $args based on multiple params?

Igor Sysoev March 25, 2009 11:59AM

Re: Redirect on $args based on multiple params?

Maxim Dounin March 25, 2009 01:58PM

Re: Redirect on $args based on multiple params?

Igor Sysoev March 25, 2009 06:17PM

Re: Redirect on $args based on multiple params?

Maxim Dounin March 26, 2009 06:35AM

Re: Redirect on $args based on multiple params?

Igor Sysoev April 04, 2009 01:54PM

Re: Redirect on $args based on multiple params?

Phillip B Oldham March 26, 2009 04:35AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 227
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready