4

I want to add php code to my .html file. I have searched a lot and din't find why it is not working

Steps i have followed for this:

1) Created a .htaccess file inside my htdocs

2) And added the following things

  AddType text/html .shtml .shtm .htm .html
  AddHandler application/x-httpd-php5.6 .html

3) Restarted my Apache.

Executed my page. My page contains

<?php
 echo "hello";
?>

I din't see any errors and hello too. And i changed the htaccess content to

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

as mentioned here

It is also not working. I don't know whether htaccess file must contain some other elements or not. Please let me know.

Thanks

Community
  • 1
  • 1
Gibbs
  • 16,706
  • 11
  • 53
  • 118

2 Answers2

1

You need to set AllowOverride to All in httpd.conf, or in your virtual hosts file (httpd-vhosts.conf) if you are using them.

Otherwise, directives in your .htaccess file will not be allowed.

More information can be found here: http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

Update

If it is set to All, then you should be able to do either of the following.

Unset the handler and reset it:

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

Or, use FilesMatch:

<FilesMatch "\.(htm|html|php)$">
    SetHandler application/x-httpd-php
</FilesMatch>
Mike Rockétt
  • 8,617
  • 4
  • 40
  • 81
0

Try this :

AddHandler application/x-httpd-php .html
Amit Verma
  • 38,175
  • 19
  • 80
  • 104