# Enable rewriting
RewriteEngine On

# Make sure the .htaccess file is in the same directory as your PHP files

# Redirect URLs ending with .php to remove the extension
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

# Internally rewrite clean URLs to their .php counterparts
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]

# Optional: if you want to handle URLs with multiple segments like /folder/page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ $1.php [L]
