DirectoryIndex index.php

RewriteEngine On

# Canonical redirect: /page.php -> /page (so old bookmarked .php links still work)
RewriteCond %{THE_REQUEST} /([^.\s]+)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]

# Serve existing files/directories as-is (css, js, images, etc.)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# /page -> page.php, served internally (URL stays clean)
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
