I'm serving a static HTML site with Nginx using the following configuration:
server {
# some configs
# Web root and file handling
location / {
root /var/lib/jenkins/workspace/test;
index index.html index.htm;
try_files $uri $uri.html $uri/ /index.html;
}
}
I want to remove .html from the URLs, so I added this rewrite rule:
location ~ ^/(.*)\.html$ {
rewrite ^/(.*)\.html$ /$1 permanent;
}
This works fine for pages like /test.html, which are rewritten to /test. However, whenever I access the root URL /, the browser displays /index in the address bar, which is not what I want. I want the root URL to remain as /.
How can I prevent /index from being appended to the root URL while keeping the .html rewrite for other pages?