我要关闭一个网站,我需要 nginx 将所有用户重定向到根目录,而不仅仅是在所有网站网址上向他们显示相同的页面。
现在我有这个:
server {
listen 80;
root /var/www/mysite;
rewrite ^.*$ /index.html last;
}
但是这不会重定向,而是显示 index.html
内容无处不在。
如何进行重定向以便 mysite.com/somepage
将重定向到 mysite.com
反过来,它会显示index.html页面?
最佳答案
以下内容应该满足您的要求:
server {
listen 80;
root /var/www/mysite;
location = / { try_files /index.html = 404;}
location / { rewrite ^ / permanent; }
}
关于redirect - 如何告诉nginx将网站的所有页面重定向到root?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14937879/