# Enable rewrite engine
RewriteEngine On


# Route root to index.php
RewriteRule ^$ index.html [L]

# Skip rewriting for actual files and directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Hide .php extension
# If request doesn't end with .php and the PHP file exists, route to it
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

# Redirect requests with .php extension to clean URLs
RewriteCond %{THE_REQUEST} ^GET\ /(.*)\.php(\?.*)?\ HTTP
RewriteRule ^(.*)\.php$ /$1 [R=301,L]


# Hide .html extension
# If request doesn't end with .php and the PHP file exists, route to it
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]

# Redirect requests with .html extension to clean URLs
RewriteCond %{THE_REQUEST} ^GET\ /(.*)\.html(\?.*)?\ HTTP
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

