My files on disk have extensions: index.html , a.html . I want the request http://example.com/a download /var/www/a.html and http://example.com/ to download /var/www/index.html . I want any other URL to be redirected to the canonical URL, so http://example.com/a.html should be redirected to http://example.com/a .
My configuration looks like this:
rewrite ^(/.+)\.html$ $scheme://$host$1 permanent; location / { root /var/www; try_files $uri.html $uri $uri/ =404; }
This redirects /a.html to /a and a.html when loading a.html from disk:
$ curl -D- -s http://www.jefftk.com/food.html | grep ^Location Location: http://www.jefftk.com/food $ curl -s http://www.jefftk.com/food | grep ^Location
But it sends / to /index :
$ curl -s -D- http://www.jefftk.com/pictures/ | grep ^Location Location: http://www.jefftk.com/pictures/index $ curl -s -D- http://www.jefftk.com | grep ^Location Location: http://www.jefftk.com/index
If I delete the rewrite rule, it stops redirecting from /a.html to /a , but also stops sending / to /index to /index :
$ curl -D- -s http://www.jefftk.com/food.html | grep ^Location $ curl -D- -s http://www.jefftk.com/food | grep ^Location $ curl -D- -s http://www.jefftk.com/ | grep ^Location $ curl -D- -s http://www.jefftk.com/pictures/ | grep ^Location
Why is this going to happen? Can I do nginx for both things I want (extension .html , no index in url) at the same time?
source share