【问题标题】:html page not reading php - ignoring .htaccess instructionshtml 页面未读取 php - 忽略 .htaccess 指令
【发布时间】:2022-02-15 05:23:59
【问题描述】:

在将我的 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/$1 [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/$1 [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/$1 [R,L]

【问题讨论】:

  • 我注意到您的自定义 AddHandler 语句使用的 MIME 类型与显然由 cPanel 自动生成的 MIME 类型不同,您是否尝试过使用 application/x-httpd-ea-php74
  • 究竟做了哪些更改?您能否分享上一个工作配置以及您应用的更改?
  • 我会试试的,Jan,然后报告。谢谢
  • Nico -- 从上一个文件更改,将 php 版本升级到 7.4 的块,以及下面的 AddHandlers 从 php5 更改为 php7

标签: php html apache .htaccess


【解决方案1】:

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

我注意到您的自定义 AddHandler 语句使用的 MIME 类型与显然由 cPanel 自动生成的 MIME 类型不同,您是否尝试过使用 application/x-httpd-ea-php74

【讨论】:

    猜你喜欢
    • 2013-01-29
    • 1970-01-01
    • 2020-04-14
    • 2020-02-09
    • 1970-01-01
    • 2021-04-11
    • 2014-05-12
    • 2014-01-06
    • 2010-10-27
    相关资源
    最近更新 更多