html 页面未读取 php - 忽略 .htaccess 说明

html page not reading php - ignoring .htaccess instructions

将我的 php 版本从 5.6 升级到 7.4 并修改我的 .htaccess 文件以确认新版本后,我的 html 页面未处理其 php 代码。换句话说,输出 php 代码本身而不是其预期的计算。所有 php 代码在版本升级前工作正常。

在修改后的 .htaccess 文件中,版本 7 替换了 AddHandlers 中的版本 5。我使用 phpinfo 检查 php 版本是否确实正确。没错。

我知道我页面上的代码是正确的,因为当该页面使用 .php 扩展名代替 .html 扩展名时,它会正常运行。它在版本升级之前运行良好。我修改后的 .htaccess 有什么问题?首先,这是我修改后的 .htaccess 文件:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/ [R,L]

RewriteOptions inherit
RewriteEngine On 
RewriteCond %{HTTPS} !=on 
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 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

RewriteEngine on
<Files index.html>
AddHandler application/x-httpd-php7 .html
</Files>

<Files index2.html>
AddHandler application/x-httpd-php7 .html
</Files>

<Files index-threejs.html>
AddHandler application/x-httpd-php7 .html
</Files>

...这是我的旧 .htaccess 文件,在 php 升级之前工作正常:

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

#RewriteEngine On
#RewriteCond %{HTTP_HOST} dentonrainfall\.com [NC]
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://dentonrainfall.com/ [R,L]

RewriteEngine on
<Files index.html>
AddHandler application/x-httpd-php5 .html
</Files>

<Files index2.html>
AddHandler application/x-httpd-php5 .html
</Files>

<Files index-threejs.html>
AddHandler application/x-httpd-php5 .html
</Files>

RewriteEngine Off
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://dentonrainfall.com/ [R,L]

Jan 的建议是解决方案。重复他们所说的话:

I noticed your custom AddHandler statements use a different MIME type from the one apparently auto-generated by cPanel, have you tried using application/x-httpd-ea-php74