ErrorDocument 404 /page-not-found

RewriteEngine on

# remove ".php" from URL; use THE_REQUEST to prevent infinite loops
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php([^\ ]*)\ HTTP
RewriteRule (.*)\.php([^\ ]*)$ http://%{HTTP_HOST}/$1$2 [L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php([^\ ]*)\ HTTP
RewriteRule (.*)\.php([^\ ]*)$ https://%{HTTP_HOST}/$1$2 [L,R=301]

# enforce "https://"
#RewriteCond %{HTTPS} off
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# enforce "www."
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# remove "www."
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

# remove ".php" from filenames
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L] 

