i would like to add ".html" to every document ending on "/", except from the homepage.
i have tried some different ways using rewrite and return 301 with nginx but i didn´t not get it working. attached the last version i did, which is doing /*/.html but the second / should not be there.
location / {
try_files $uri $uri/ =404;
return 301 $scheme://$host$request_uri.html;
}
Solution im am looking for:
root: domain.com should be delivered as www.domain.com
files should be redirected (301) to the *.html version
You will need to use a regular expression to capture the part of the URI before the trailing /, in order to eliminate it. One solution would be to use a named location with the try_files statement.
For example:
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^(.+)/$ $1.html permanent;
}
See this document for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With