21

I have the included code in my .htaccess file but the php code I am attempting to include is not working.

Options +Includes
AddType text/html  .htm .html
AddHandler server-parsed .htm .html
AddType application/octet-stream .vcf
AddOutputFilterByType DEFLATE text/html text/htm text/plain text/css text/php    text/javascript application/x-javascript
0

23 Answers 23

34

Try:

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

UPDATE 1

It may be PHP version specific. If you're using PHP5 try:

AddType application/x-httpd-php5 .html .htm

UPDATE 2

Try:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Or here's yet another alternative way to do this:

<FilesMatch "\.html$">
    ForceType application/x-httpd-php
</FilesMatch>
6
  • I went ahead and tried that and when I went to reload the page, chrome downloaded a file called "download." This was working the other day so I'm stumped.
    – Ben G
    Commented Jun 9, 2011 at 15:34
  • I am using PHP5, however chrome is still attempting to download a file after I make the change. I apologize for being clueless here, I'm fairly new to working within .htaccess. Is there any more information I can provide that would help answer the question more effectively?
    – Ben G
    Commented Jun 9, 2011 at 15:50
  • I'm not much of a server admin so I am unsure why it isn't working for you. But I added another way to do this to my answer. Hopefully it helps.
    – John Conde
    Commented Jun 9, 2011 at 15:52
  • Still not working. Thanks for your help, I may just have to contact the old webdev I just replaced to figure out what is causing his backend to do this.
    – Ben G
    Commented Jun 9, 2011 at 16:02
  • 1
    RemoveHandler .html .htm AddType application/x-httpd-php5 .html .htm worked for me
    – raglan
    Commented Apr 10, 2014 at 20:32
19

On Apache 2.2.22 (Ubuntu) with Php 5 add these lines to /etc/apache2/mods-enabled/php5.conf

<FilesMatch ".+\.html$">
    SetHandler application/x-httpd-php
</FilesMatch>

and restart apache

sudo service apache2 restart
1
  • Meh, works for local server but I'd hate to have this problem on a live server/shared where the host would just flat-out refuse.
    – John
    Commented Apr 24, 2015 at 19:14
8

For godaddy shared hosting (php-cgi):

From http://sagarnangare.com/parse-html-as-php-using-htaccess-file-on-godaddy/

AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

That's the only one that worked for me.

0
6

If you are using Plesk Control Panel:

PHP is running as an Apache module:

<IfModule mod_php5.c>
   AddHandler php5-script .php .html .htm
   AddType text/html .php .html .htm
</IfModule>

PHP is running as a FastCGI application:

<IfModule mod_fcgid.c>
    <Files ~ (\.html)>
        SetHandler fcgid-script
        FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
        Options +ExecCGI
        allow from all
    </Files>
</IfModule>

PHP is running as a CGI application:

<Files ~ (\.html)>
    SetHandler None
    AddHandler php-script .html
    Options +ExecCGI
    allow from all
</Files>

Then /usr/local/psa/admin/sbin/httpdmng --reconfigure-all

http://kb.odin.com/en/115773

2
  • You my friend are a life saver! 'PHP is running as a CGI application' was giving me an issue since we changed from Apache Module and our PHP version upgraded. Commented Feb 17, 2017 at 18:22
  • I can confirm the FastCGI solution for Plesk 12.5. But like to add that the <IfModule> condition must be wrapped in <Directory /path/to/my/vhost/root><IfModule mod_fcgid.c>...<IfModule></Directory>
    – con
    Commented Jun 26, 2017 at 14:06
5

VERY IMPORTANT that you must replace the "php5" to your OWN exact PHP version in the:

AddHandler application/x-httpd-php5 .html .htm

AddType application/x-httpd-php5 .html .htm

Because I have tried everithing in every way from all over the web, but nothing worked until I found a "MultiPHP Manager" menupoint under my CPanel, and under this I found out that my exact PHP version/name/id (or whatever it is called) was "ea-php56", so my working code is:

AddHandler application/x-httpd-ea-php56 .html .htm

AddType application/x-httpd-ea-php56 .html .htm

I have browsed all day the forums, comments, but I haven't found this very important information anywhere, so maybe You also have to look up your exact PHP version if it is not working!

4

If your server is using PHP5 then use this:

AddHandler application/x-httpd-php5 .html .htm

If it's not PHP5 then use

AddHandler application/x-httpd-php .html .htm

It worked for me on CPanel hosting.

If you are using some other linux hosting try this:

<IfModule mod_mime.c>
AddType application/x-httpd-php .html .php .htm
</IfModule>

Options +FollowSymlinks
2

For Godaddy server it worked for me

Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
0
1

BenG, did any solution ever work for you?

this may help -- i found this topic confusing, because either statement worked for me in my local dev environment

AddHandler application/x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm

after reading the apache documentation on both directives, it seems that you want to use AddType when adding a mime type not yet handled by apache, and AddHandler when you want apache to handle a file differently than its default handling of that file type. i may be wrong, but that does seem to be what the manual is saying.

so if you want apache to handle .html and .htm as if they were .php files then you would use the directive :

AddHandler application/x-httpd-php .html .htm

the .htaccess file you mention above is doing a few things, so maybe you could first verify that it does indeed tell apache to handle .htm and .html files as if they are .php files; then move on to the other directives you want to use.

1

I was stumped for 2 hours until I looked into /etc/php/7.2/fpm/pool.d/www.conf and then uncommented the security setting to force php to only parse php and added .html so that the line now is security.limit_extensions = .php .php3 .php4 .php5 .php7 .html and then sudo service php7.2-fpm restart and doing the

<head>
</head>
<body>
    This should show date here:

<?php echo date('l, F jS, Y'); ?>
</body>

and saved as test.html worked fine and displayed!

1
  • 1
    On a Fedora 36 server runnig PHP 8.1.8 in late 2022 this was the solution for me. The exact file I needed to edit was /etc/php-fpm.d/www.conf. No AddType or AddHandler settings were needed in other files, just this one FPM setting "security.limit_extensions = .php .html".
    – Night Owl
    Commented Nov 8, 2022 at 7:46
0

From http://support.lunarpages.com/knowledge_bases/article/321

How can I configure Apache to treat .html files as PHP under suPHP? You need to remove any previous entries for handling .html files as PHP and insert the following in your .htaccess file: AddHandler x-httpd-php .html .htm Or you can add this manually using Cpanel -> Apache Handlers -> New: Extension: .html .htm Handler: x-httpd-php The newest cPanel servers actually require the following instead: AddHandler application/x-httpd-php .html .htm or AddType application/x-httpd-php .html .htm Please try this if the first type doesn't work for you for files.

0

You can just try to put only this AddType php .html .htm to your htaccess, If this AddType application/x-httpd-php .html .htm doesn't work.

0

Don't know if it helps but... My example after hour of searching:

AddType application/x-httpd-php .php
LoadModule php5_module "c:/server/php5/php5apache2_2.dll"
ScriptAlias /_php/ "c:/server/php5/"

in httpd.conf

Without LoadModule and ScriptAlias it didn't process php at all and showed plaintext

0

Been stumped by this a lot before and what probably is happening, if none of the others worked, is your reading it as a file and not going through apache. Check your address bar and make sure it starts with localhost, your ip, 127.0.0.1, or your domain name if you've already set it up to direct to your server.

0

If you are trying to run very old PHP code, make sure you have

short_open_tag = On

in your php.ini

or, even better (because it's not recommended to use short open tags for new code anymore) to enable for specific virtual host only via:

php_value short_open_tag On

in httpd.conf / .htaccess file.

0

You might want to try adding this line to your .htaccess file:

AddHandler x-mapp-php6 .html .htm
1
  • While this may answer the question, it would be best if you could provide a little explanation for why it does so. Commented Jan 22, 2016 at 8:58
0

simplify to 3 steps:

  1. vim /etc/httpd/conf/httpd.conf

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

  3. service httpd restart

0

I am using GoDaddy dedicated server with Plesk. Here is what I have to use to get it to work:

AddHandler fcgid-script .htm
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .htm

For the actual path of the cgi_wrapper, refer to the file:

/var/www/vhosts/yourdomain.com/conf/last_httpd.include
or /etc/httpd/conf.d/php_cgi.conf

0

Adding this to .htaccess solved my problem, using PHP 5.5:

AddType application/x-httpd-php .html
0

PHP is running with SuPHP:

<FilesMatch "\.html$">
    SetHandler application/x-httpd-php
</FilesMatch>
0

AddHandler application/x-httpd-ea-php56 .html .htm

AddType application/x-httpd-ea-php56 .html .htm

this worked for me!

0

if you want url for www.examle.com/page.php?id=123&lang=it in seo like this www.examle.com/it/1/2/3/pagina.html add in .htaccess

<Files it>
SetHandler php-script
</Files>
<Files ru>
SetHandler php-script
</Files>

and when create files "it" "ru" in web http root directrory like this:

<?php
   // www.examle.com/it
   $lang="it";
   include("urlrewrite.php"); 
?>
<?php
   // www.examle.com/ru
   $lang="ru";
   include("urlrewrite.php"); 
?>
0

For PHP version 5.6.40 run PHP as "FRM application served by Apache" ( Plesk ) add this in .httaccess

<FilesMatch "\.html$">
   SetHandler php-script
</FilesMatch>

it's work for me

0

Open "MultiPHP INI Editor" from the cpanel then enable "allow_url_include"

then add the below lines to your .htaccess file:

<IfModule mod_mime.c>
AddType application/x-httpd-ea-php73 .html .php .htm
</IfModule>
Options +FollowSymlinks

Important: must replace the php ver with yours

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.