Rewrite rules from Apache again

Francis Daly francis at daoine.org
Wed Jun 11 17:05:50 UTC 2014


On Wed, Jun 11, 2014 at 06:20:50PM +0200, Luciano Mannucci wrote:
> On Tue, 10 Jun 2014 22:43:05 +0100
> Francis Daly <francis at daoine.org> wrote:

Hi there,

> > The rest of the config?
> :)
> Well, I've posted it in my previous request for help. Beeing
> longish I tried to spare some bandwith... :)

No worries.

It can be useful to have a minimal test case that shows the problem.

> I had it under "location /"
> Moving it to "server" level and adding a "break" seems to make it work!

Very approximately, the order is:

choose the server{}
 run the rewrite directives
 choose the location{}
  run the rewrite directives, looping back as necessary
  handle the request

So your non-server-level rewrites will only apply if they are in the
location{} that is chosen.

> >   location = /pagina.php {
> >     return 200 "I got $uri$is_args$args from $request_uri\n";
> >   }
> Many thanks for this elegant way of debugging this kind of
> configuration problems.

You're welcome.

You may also find it useful to enable debug logging for your test client,
such as by putting something like

  debug_connection 127.0.0.10;

within the events{} block, and then looking in error_log.

> If I try the same thing in a subdirectory, it doesn't work.

Put the rewrites at server{} level, or in the location{} that is chosen.

> It seems that the "location =" that I've put to intercept the rewrite
> doesn't match.

No.

The rewrite that you want doesn't happen, because the request
/en/privacy.php is handled in:

>         location ~ \.php$ {
>         location / {
>         location ^~ /en/ {
>             location = /en/pagina.php {
>             location ~ \.php$ {

...that location, and not in the one two above it.

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list