RewriteEngine On

# Remove .html extension and internally rewrite to .html file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/.]+)$ $1.html [L]

# Remove .php extension and internally rewrite to .php file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/.]+)$ $1.php [L]

# Redirect requests to non-extension URLs to extension URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/.]+)$
RewriteCond %{REQUEST_URI}.html -f
RewriteRule ^ /%1.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/.]+)$
RewriteCond %{REQUEST_URI}.php -f
RewriteRule ^ /%1.php [L]
