When I rewrite the URL by adding a query string, the URL in the browser does not have the query string. Here's what I have:
location / {
rewrite ^/$ /?page=test break;
}
Instead, I see the original URL in the browser when I visit the root directory. I am able to rewrite to another path.
As written, this is only a rewrite, which is (and should be) handled internally by the web server without the user being aware of it.
You can make this user-visible either temporarily or permanently by adding the
redirect
orpermanent
statements to your rewrite line (nginx doc for rewrite).Be careful with the
permanent
variant (HTTP Code 301), the name is quite literal and the browser will store this so it's hard to change this afterwards - this should only ever be used to migrate to a new system.Using
redirect
will force the browser to reload the site with the new URL, so this should be used with care as well, as it will add a significant delay to your page load times.This issue is happening because of this. rewriting with a query string works.