Options -MultiViews
RewriteEngine On

# Redirect explicit .html URLs to extensionless paths.
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html(?:[\s?]|$) [NC]
RewriteRule ^ %1 [R=301,L]

# Serve real files/directories directly.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Route extensionless paths to matching .html files.
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

DirectoryIndex index.html
