# Enable URL rewriting
RewriteEngine On

# Remove .php extension from URLs
# Don't rewrite if the request is for an actual directory
RewriteCond %{REQUEST_FILENAME} !-d
# Don't rewrite if the request is for an actual file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite to .php if the file exists
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

# Redirect .php extension to clean URL (301 permanent redirect)
# But exclude config directory (API endpoints should keep .php extension)
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteCond %{REQUEST_URI} !^/admin/config/ [NC]
RewriteRule ^ /%1 [R=301,L]
