-2

I am trying to run a simple php code inside my html file. The file name is test.html. The following code is inside the file:

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
 echo "Hello World!";
 ?>

</body>
</html>

I have also changed my .htaccess file to include a code which my service provider recommended which is: AddHandler x-httpd-php .html. But I still cannot display a simple message. Everything works fine if I change the file name to .php. But I want to keep my file name .html. I can provide more info if required.

Learningmind
  • 137
  • 1
  • 1
  • 6
  • 5
    It's `AddHandler`, not `AddHandled`, there's a typo. – Tomasz Kowalczyk Nov 28 '14 at 01:21
  • Yes, that's a typographical error. `AddHandler` is the correct syntax. – worldofjr Nov 28 '14 at 01:28
  • Where is your .htaccess file ???? – Kanishka Panamaldeniya Nov 28 '14 at 01:29
  • It's located in the public folder. I am also placing my test.html file there. – Learningmind Nov 28 '14 at 01:42
  • `.htaccess` is sometimes tricky for seemingly no reason, since some things depend upon the server configuration. On that note, you could try asking on `http://serverfault.com/`. You could try `AddHandler fcgid-script .html` if using fast cgi. Or depending on your control panel use your control panel 'Add Extensions' tool (if available). – Reed Nov 28 '14 at 15:39
  • Something that will work (but isn't necessarily the "right" way) is if you add to your `.htaccess` `RewriteRule ^([^.]+)\.html$ /router.php`, then `router.php` in your root directory (public_html) will be loaded where you can do `include('/home/username/public_html'.$_SERVER('REQUEST_URI'));` BUT, you should use `realpath` and then make sure the path still starts in `/home/username/public_html` in case of `/../` in the request uri. – Reed Nov 28 '14 at 15:43

1 Answers1

0

Try

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

or

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

or

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

or

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

Instead of

AddHandler application/x-httpd-php .html .htm 
Kanishka Panamaldeniya
  • 16,046
  • 27
  • 109
  • 185
  • I have tried all variant mentioned above except one that includes RemoveHandler. I will try that and see if it works. – Learningmind Nov 28 '14 at 01:44
  • 1
    If it still doesn't pick up your htaccess rules then apache is not set to allow override from htaccess. You need to set your virtual host to allow that before htaccess can take effect – Hanky Panky Nov 28 '14 at 01:59
  • Still not working. Man I don't know why this simple thing is so difficult. – Learningmind Nov 28 '14 at 07:00