Coming from an Apache background, in the past I have hidden .html file extensions using a pair of rewrite rules:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /.+\.html\ HTTP
RewriteRule ^(.+)\.html$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^.+$ %{REQUEST_FILENAME}.html [L]
nginx's rewriting capabilities are different, a possible solution lies here however, the nginx wiki suggests that if at all possible avoiding ifs is the best solution, and discusses using (try_files
) instead. I was wondering whether anyone had the best way to implement something like this, as whilst:
try_files $uri $uri.html =404;
works in some cases, you would get massive redirect problems etc. Is there any way to avoid ifs in this case?