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/path?somearg=something
.
But when I have an url like this http://www.mydomain/path/?somearg=something
nginx redirects(301) to http://www.mydomain/index.php/HASH/path?somearg=something
, and index.php and HASH are exposed.
I tried something like this:
location @mylocation {
if (-d $request_filename) {
rewrite ^/(.*)$ /$controller/$siteName last;
break;
}
if ($request_filename ~ "") {
#not sure what to put here
}
if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css)$") {
rewrite ^/(.*)$ /$controller/$siteName/$1 last;
}
}
But I'm unsure what to put in the second if block in order to avoid the redirect.
Any help is appreciated, thanks.