In the past a project was getting moved from /
to /subdir
. As the old URL structure was something like /index.php?foo/123/bar
I used the following rewrite to get everything to /forum
:
rewrite ^\/index\.php(.*)$ /forum/$1 last;
The problem with this rewrite is that it also redirects /
to /forum/
and /index.php
to /forum/
. Now I want to not redirect them because there has been created a new start page in /
.
So /
should not be redirected but if there is a query string it should.
I tried the following:
location / {
if ($query_string !~ "") {
rewrite ^\/index\.php(.*)$ /forum/$1 last;
}
try_files $uri $uri/ @rewrite;
}
The start page works now but if there is a query string nothing gets rewritten and I don’t know why.