Gibbs
Gibbs

Reputation: 22956

Adding php code to .html file

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

Upvotes: 4

Views: 623

Answers (2)

Mike Rock&#233;tt
Mike Rock&#233;tt

Reputation: 9007

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>

Upvotes: 1

Amit Verma
Amit Verma

Reputation: 41219

Try this :

AddHandler application/x-httpd-php .html

Upvotes: 0

Related Questions