Welcome! Log In Create A New Profile

Advanced

Re: a regex for rewrite

Francis Daly
September 04, 2013 08:06PM
On Wed, Sep 04, 2013 at 06:54:06PM -0400, etrader wrote:

Hi there,

> I have a set of rewrites as
>
> rewrite ^/(.*)/(.*)/(.*)\.(.*) /script.php?a=$1&b=$2&c=$3&ext=$4 last;
> rewrite ^/(.*)/(.*)\.(.*) /script.php?a=$1&b=$2&ext=$3 last;
> rewrite ^/(.*)\.(.*) /script.php?a=$1&ext=$2 last;
> rewrite ^/(.*)/(.*)/(.*)/(.*) /script.php?a=$1&b=$2&c=$3&d=$4 last;
> rewrite ^/(.*)/(.*)/(.*) /script.php?a=$1&b=$2&c=$3 last;
> rewrite ^/(.*)/(.*) /script.php?a=$1&b=$2 last;
>
> How can I use one single rewrite rule to match all possible choices?

If you really want to do that, I'd suggest using a programming language
to do complicated programming, and using nginx.conf for simpler things.

location ~ ^/.*[/.] {
rewrite ^ /script.php?E=READ_THE_REQUEST last;
}

and then change script.php to process $_SERVER[REQUEST_URI] when it gets
the special value E=READ_THE_REQUEST, so that it populates a, b, c, d,
and ext as is appropriate.

In fact, I suspect that I'd not use rewrite at all: either fastcgi_pass
directly in this location; or proxy_pass sending the original $uri as
an argument.

(There are cases where this "location" is not a drop-in replacement for
the initial "rewrite"s. If your system is one of those, you'll need a
different plan.)


But if your rewrite system works and is clear enough for you, you probably
don't need to change it.

Good luck with it,

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

a regex for rewrite

etrader September 04, 2013 06:54PM

Re: a regex for rewrite

Francis Daly September 04, 2013 08:06PM

Re: a regex for rewrite

Francis Daly September 04, 2013 08:12PM

Re: a regex for rewrite

etrader September 05, 2013 11:20AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 130
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