I have set up a server block that looks like this:
root /var/www/platform
location / {
index index.html;
}
location /contact {
try_files $uri /contact.html;
}
This works fine. I can go to x.com/contact
and the contact.html
page loads.
Now I want to add a subdirectory products
with files like product1.html
and so on. When the user goes to x.com/products/product1
I want to load the html file.
Because the products
subdir is within the platform
directory, x.com/products/product1.html
works fine with the current ^ setup. I just want to get rid of the need to have .html
at the end.
So I try adding a location block
location /products/(product) {
root /products;
try_files /$1.html $1.html /index.html;
}
But obviously this doesn't work. Any help will be appreciated.
If there's another better (but still easy) approach, I'd love to know it too.