Options -MultiViews
RewriteEngine On
# Relative substitutions work both at the domain root and in a subfolder.

# Redirect browser requests to PHP files; leave POST bodies untouched.
RewriteCond %{REQUEST_METHOD} ^(?:GET|HEAD)$
RewriteCond %{THE_REQUEST} \s/+([^?\s]+)\.php(?:[?\s]) [NC]
RewriteRule ^(.+)\.php$ /%1 [R=301,L,NE]

# Remove trailing slashes from PHP page URLs so relative links stay correct.
RewriteCond %{REQUEST_METHOD} ^(?:GET|HEAD)$
RewriteCond %{REQUEST_FILENAME} ^(.+?)/+$
RewriteCond %1.php -f
RewriteRule ^(.+?)/+$ $1 [R=301,L]

# Resolve clean URLs to existing PHP files, including admin pages.
RewriteRule ^freelancing/?$ freelancing.php [END]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [END]
