<FilesMatch ".(?:html|php)$">
SetHandler application/x-httpd-alt-php74
</FilesMatch>
RewriteEngine On

# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/(.+)\.html\sHTTP [NC]
RewriteRule ^ /%1 [R=301,L]

# To internally forward /dir/file to /dir/file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.html [L]

# Hide PHP file extension and allow PHP execution
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)/?$ $1.php [L]

# Remove PHP file extension from URLs with query parameters
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{QUERY_STRING} !=""
RewriteRule ^([^/]+)\.php$ /$1? [L,R=301]

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
