DirectoryIndex index.html
ErrorDocument 404 /404.html
Options -Indexes

<IfModule mod_rewrite.c>
	RewriteEngine On

	# Direct client requests to a ".html" URL return 404 — only the clean,
	# extensionless URL is public. %{THE_REQUEST} holds the original request
	# line, which internal rewrites do NOT change, so the clean-URL rewrite
	# below still serves the .html file and the custom 404 page still renders.
	RewriteCond %{ENV:REDIRECT_STATUS} ^$
	RewriteCond %{THE_REQUEST} \s/+[^?\s]+\.html[\s?] [NC]
	RewriteRule ^ - [R=404,L]

	# Serve "/foo" from "/foo.html" when that file exists (clean URLs).
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{DOCUMENT_ROOT}/$1.html -f
	RewriteRule ^(.+?)/?$ $1.html [L]
</IfModule>
