# Enable rewrite engine
RewriteEngine On

# Only apply to HTML pages
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|jpeg|gif|ico)$ [NC]

# Redirect requests without trailing slash to add .html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.html [L]

# Redirect old .html URLs to clean URL
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]

# Prevent directory listing
Options -Indexes
