I have a simple static web site on Nginx, and I'm trying to implement a redirect from mysite.com/index.html to mysite.com, so it's more search engine friendly. But I get a redirect loop. I wrote this rule:
location = /index.html {
rewrite ^ http://mysite.com permanent;
}
Doing some tests, I noticed that if I redirect to the 404 page, everything is fine:
rewrite ^ http://mysite.com/404.html permanent;
This is the full configuration file:
server {
listen 80;
server_name www.mysite.com;
rewrite ^/(.*) http://mysite.com/$1 permanent;
}
server {
listen 80;# default_server;
listen ipaddress:80;
server_name mysite.com;
access_log /var/www/mysite.com/logs/access.log;
error_log /var/www/mysite.com/logs/error.log;
root /var/www/mysite.com/htdocs;
error_page 404 /404.html;
location = /index.html {
rewrite ^ http://mysite.com permanent;
}
}