Optimize rewrite

Reinis Rozitis r at roze.lv
Thu Apr 4 09:39:43 UTC 2013

> location / {
>         rewrite    ^/(.*)/(.*)$      /$1/index.php?url=$2;
>    }

I would suggest to use try_files:

location / {
        try_files $uri $uri/ /index.php?url=$uri&$args;

Personally instead of pasing the uri in the 'url' param I like to use 
try_files $uri $uri/ /index.php?$args; and then in the php code have the url 
in $_SERVER['REQUEST_URI'] (or $_SERVER['DOCUMENT_URI']) that way there is 
no possibility to accidentaly mess with the GET variables.


More information about the nginx mailing list