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.
Are you sure it's not the CMS generating the redirect? Nothing in your config or the way that nginx works would generate that kind of response.
Let's try dropping the trailing slash if one exists, and see if that placates the CMS from firing redirects?