Rewrite query string

Hey folks,

I simply can’t figure out how to rewrite the query string in nginx.
I need to turn urls like foo.php?f=111 into foo.php?111 and similar
things.
From reading past messages in the lists it seems like I can only match
on query string with the “if” but
there’s no way to rewrite the query string itself.
Is that still correct? No workaround available?

Thanks in advance,

thomas

Hi Thomas, I’m not clear whether you want to do this as a server-side
rewrite or just redirect the browser, but either way
http://wiki.codemongers.com/NginxHttpRewriteModule
might help.

cheers
i

Hi Igor,

thanks for your reply.
Actually I’d need both :).
The problem with the built in rewrite module seems to be that it can’t
rewrite the request arguments (?f=something), only the raw uri (I could
rewrite foo.php to bar.php for example).

Any ideas how to rewrite the query string part?

Regards,

thomas

Igor C. schrieb:

On Mon, May 12, 2008 at 03:26:12PM +0200, Thomas S. wrote:

Hi Igor,

thanks for your reply.
Actually I’d need both :).
The problem with the built in rewrite module seems to be that it can’t
rewrite the request arguments (?f=something), only the raw uri (I could
rewrite foo.php to bar.php for example).

Any ideas how to rewrite the query string part?

What does nginx with PHP - proxy or fastchi ?

You may change $args using:

  if ($args ~ ....) {
      set   $args   ...;
  }

Hi Igor,

thanks for your reply.

o rewrite the query string part?

What does nginx with PHP - proxy or fastchi ?

fastcgi, now even running through ngx_http_upstream for multiple
balanced backends - well done with that :).

You may change $args using:

  if ($args ~ ....) {
      set   $args   ...;
  }

and I got access to the matching parts there with $1, $2 and so on?
Sounds like the way to go then, great. Thanks.

Regards,

Thomas

On Mon, May 12, 2008 at 05:01:34PM +0200, Thomas S. wrote:

Hi Igor,

thanks for your reply.

o rewrite the query string part?

What does nginx with PHP - proxy or fastchi ?

fastcgi, now even running through ngx_http_upstream for multiple
balanced backends - well done with that :).

In FastCGI you may change not just $args, but some your variable and
then use it in

fastcgi_param QUERY_STRING $your_var;

proxy requires to change exactly $args.

You may change $args using:

 if ($args ~ ....) {
     set   $args   ...;
 }

and I got access to the matching parts there with $1, $2 and so on?
Sounds like the way to go then, great. Thanks.

Yes.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs