# Disable MultiViews to prevent conflicts with mod_rewrite
Options -MultiViews

# Turn on the rewrite engine
RewriteEngine On

# Set the base path for the rewrite rules
RewriteBase /

# Rule to externally redirect /page.html to /page
# This is for users who might type the full .html address
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.html
RewriteRule ^(.+)\.html$ /$1 [R=301,L]

# Rule to internally rewrite /page to /page.html
# This is the main rule that makes the clean links work
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L]
