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

10
  • Is the opening php tag just a typo? It should be without spaces: <?php. Commented Apr 27, 2015 at 10:45
  • Have you tested with a .php file? Does that work? Commented Apr 27, 2015 at 10:51
  • I have a .php file in the same place. It works. Do i need to something else so that it checks htaccess file Commented Apr 27, 2015 at 10:51
  • 1
    Perhaps AddType application/x-httpd-php5 .htm .html would do the trick? Commented Apr 27, 2015 at 10:52
  • @MikeAnthony No I tried that too Commented Apr 27, 2015 at 10:54

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

7 Comments

Let me check this. <Directory /> AllowOverride all Require all denied </Directory> What is that require all denied.
It should be require all granted - that's what I use in mine... From which file is that?
And are you using a virtual host?
No Mike. AllowOverride All Require all granted I just added this and it doesn't work :(
Please see the update in my answer. If it still doesn't work, then I might be missing something too...
|
0

Try this :

AddHandler application/x-httpd-php .html

4 Comments

Something else? is the mod_mime enabled?
Either that, or check that AllowOverride is set to All in httpd.conf or your virtual host file if other htaccess directives are not loading.
LoadModule mime_module modules/mod_mime.so is enabled. But not mod_mime magic.
@MikeAnthony it is set to None.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.