Adding php code to .html file

I want to add php code to my .html file. I searched a lot and couldn't find why it doesn't work.

The steps I 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) Restart my Apache.

Executes my page. My page contains

<?php
 echo "hello";
?>

      

I don't see any errors and hello. And I changed the content of the htaccess to

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

      

as mentioned here

It also doesn't work. I don't know if the htaccess file should contain some other elements or not. Please let me know.

thank

+3


source to share


2 answers


You need to set AllowOverride

to All

in httpd.conf

or to your virtual hosts ( httpd-vhosts.conf

) file if you are using them.

Otherwise directives in your file .htaccess

will not be allowed.

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

Update

If set All

, you should be able to do one of the following.



Detach 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>

      

+1


source


Try the following:



AddHandler application/x-httpd-php .html

      

0


source







All Articles