Rewrite rule and the try_files directive

Edho Arief edho at myconan.net
Fri May 25 13:00:25 UTC 2012


On Fri, May 25, 2012 at 7:01 PM, Captain_Quor <nginx-forum at nginx.us> wrote:
> Hi guys,
>
> I'm a little stuck here and wondered if anyone could help, I have a
> customer's website with the following rewrite rule:
>
> 'rewrite ^/(.*)$ /index.php?town=$1 last;'
>
> This has functioned just fine until they've added three smaller
> management sites that they want to be able to reach by appending either
> /mms, /admin or /newsletter to the end of the URL (I have tried to steer
> them towards subdomains but to no avail!) now these are obviously being
> picked up by my rewrite rule and as the website doesn't recognise these
> as "towns" it's simply redirecting them back to the home page.
>
> Does anyone know a clean way of achieving this, I was originally looking
> at an 'if' statement but I've been warned off this when it comes to
> nginx due to the obvious reasons, I've been looking in to the try_files
> directive but I'm still a little unsure as to how it actually works.
>

location /admin/ {
  ...
}
location /mms/ {
  ...
}
location /newsletter/ {
   ...
}
location / {
  rewrite ...
}



More information about the nginx mailing list