Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell nginx to redirect all pages of the website to root? [closed]

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?

like image 638
snitko Avatar asked Feb 18 '23 11:02

snitko


1 Answers

The following should do what you want:

server {
  listen 80;

  root /var/www/mysite;
  location = / { try_files /index.html = 404;}

  location / { rewrite ^ / permanent; }
}
like image 129
cobaco Avatar answered May 01 '23 10:05

cobaco