Home > Software design >  html page not reading php - ignoring .htaccess instructions
html page not reading php - ignoring .htaccess instructions

Time:02-15

After upgrading my php version from 5.6 to 7.4, and revising my .htaccess file to acknowledge the new version, my html page is not processing its php code. In other words, the php code itself is output instead of its intended calculations. All php code worked fine before the version upgrade.

In the revised .htaccess file, version 7 replaced version 5 in the AddHandlers. Using phpinfo I checked to see if the php version was in fact correct. It was correct.

I know the code on my page is correct because it runs as it should when that page uses a .php extension in place of the .html extension. It worked fine prior to the version upgrade. What is wrong with my revised .htaccess? First, here is my revised .htaccess file:

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>

...and here is my old .htaccess file that worked fine before the php upgrade:

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]

CodePudding user response:

Jan's suggestion was the solution. To repeat what they said:

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

  • Related