如何允许使用 .htaccess 在 HTML 文件中执行 PHP

How to allow execution of PHP in HTML file using .htaccess

我想 运行 .html 文件作为 .php,但似乎无法正常工作。我尝试将以下所有内容一次添加到我的 .htaccess 文件中。 None 以下似乎有效。

AddType application/x-httpd-php .html .htm
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php72 .html .htm
AddHandler application/x-httpd-php5 .html .htm
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
<FilesMatch "\.html$">
 ForceType application/x-httpd-php
</FilesMatch>
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Options +ExecCGI
 AddType application/x-httpd-php .php .html
 AddHandler x-httpd-php5 .php .html

I know PHP works since I was able to create a document .php and view the version on the website using:

<?php
echo 'Current PHP version: ' . phpversion();
?>

它返回:"Current PHP version: 7.2.21"

一些值得注意的信息:我在 Bluehost 上托管网站,.htaccess 文件目前看起来像这样:

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

你试过吗?

RewriteRule ^([^\.]+)$ .html [NC,L]

看看:https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/