0

Why? Because the ancient, original file was .html and has been spidered by Google, etc.

I have an .html file that contains some php code. For my older version of PHP/Apache, I had some .htaccess lines that took care of this. Since upgrading to the latest, this no longer works. I've tried a half-dozen suggestions (AddType, AddHandler, RewriteRule) for how to do this in the hopes that it will work with PHP 7.4 and Apache/2.4.46, but nothing seems to work. What works on the above configuration? All permutations cause clicking on a link to the .html file for it to be downloaded by the browser - and it's just the raw file (you can see the php code within it).

btw: phpInfo says Server API: "FPM/FastCGI"

Works on PHP 5.6 (but not on PHP 7.3/7.4)

AddHandler php5-script .php .html .htm

Works on PHP 7.3 (but not on PHP 7.4)

AddHandler application/x-httpd-php .html

Fails on PHP 7.4 (each tested individually, just one line in the .htaccess file)

AddHandler application/x-httpd-php .html
AddType application/x-httpd-php .html
AddHandler php-script .php .html .htm
AddHandler fcgid-script .php .htm .html
AddHandler php7-script .php .html .htm
AddHandler php7.4-script .php .html .htm
AddHandler php70-cgi .php .html
AddHandler php74-cgi .php .html
AddType x-mapp-php4 .html .htm
AddHandler FPM/FastCGI .php .html
<FilesMatch ".+\.html?$">
  SetHandler application/x-httpd-php
</FilesMatch>

I'm testing by directly modifying the .htaccess file on the server and clicking on the link to the .html page within a browser, no refreshes or restarts of anything.

btw: this combination of PHP and Apache is one of the options provided by AWS Elastic Beanstalk, which is where this is running

Thanks!

Peter

  • Have you tested: SetHandler application/x-httpd-php – jacouh Apr 09 '21 at 21:00
  • @jacouh I just tried that, and there is no change. – Peter Jones Apr 09 '21 at 23:09
  • Have you loaded LoadModule php7_module /usr/lib/apache2/modules/libphp7.4.so, by testing index.php if working ? – jacouh Apr 10 '21 at 20:05
  • Does this answer your question? [Using .htaccess to make all .html pages to run as .php files?](https://stackoverflow.com/questions/4687208/using-htaccess-to-make-all-html-pages-to-run-as-php-files) – Don't Panic Apr 12 '21 at 10:11
  • @jacouh I don't know about LoadModule, I'm assuming the configuration of Apache itself is correct as .php files work fine. Plus, I can't believe that AWS would set the default configuration of Apache to deny the ability to send .html files through the php parser. – Peter Jones Apr 13 '21 at 17:34
  • conf.d/elasticbeanstalk/php.conf has this, but unfortunately a variant for .html does not work when placed into .htaccess # # Cause the PHP interpreter to handle files with a .php extension. # SetHandler application/x-httpd-php – Peter Jones Apr 13 '21 at 18:13

2 Answers2

0

Try this, it should work for PHP 7.4

AddHandler application/x-httpd-php74 .php .html
emadelbieh
  • 336
  • 1
  • 4
0

Try this:

AddType application/x-httpd-lsphp .php .html

That is not just -php but -lsphp

stckvrw
  • 1,689
  • 18
  • 42