I'm closing down a website and I need nginx to redirect all users to the root and not just show them the same page on all website urls.
For now I have this:
server {
listen 80;
root /var/www/mysite;
rewrite ^.*$ /index.html last;
}
However this doesn't redirect, but rather shows index.html
content everywhere.
How do I do a redirect so that mysite.com/somepage
would redirect to mysite.com
which, in turn, would show index.html page?
The following should do what you want:
server {
listen 80;
root /var/www/mysite;
location = / { try_files /index.html = 404;}
location / { rewrite ^ / permanent; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With