nginx is redirecting instead of rewriting when there is a slash befor arguments

view full story

http://serverfault.com – I have the following location block, as part of a complex routing for a CMS: location @mylocation { if (-d $request_filename) { rewrite ^/(.*)$ /$controller/$siteName last; break; } if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css)$") { rewrite ^/(.*)$ /$controller/$siteName/$1 last; } } $controller is something like "index.php" and $siteName is a hash identifying the specific site in the cms. It is working fine, nginx rewrites http://www.mydomain/path?somearg=something to http://www.mydomain/index.php/HASH (HowTos)