Optimize rewrite

hello

I have a script that works with apache but I want to migrate to nginx, I
have this rule, but maybe you can do differently optimized.

HTACCESS

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ index.php?url=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ index.php [QSA,NC,L]

NGINX

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

Thanks !!

Regards

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.

rr

Ok, thanks !!! :wink:

2013/4/4 Reinis R. [email protected]