0

I have an issue parsing PHP in HTML Files.

I am using an install of Vesta and the domain is running fine. The site in question has

AddType application/x-httpd-php4 .htm .html
# and 
AddType application/x-httpd-php5 .htm .html

in the , which before I moved server it was allowing php to run in html. I have also tried every single variant of this which I have found on stack overflow and none of them are working.

I can't figure out for the life of me why its not now working?

Has anybody got any ideas? Thank you Dan Williams

Martijn
  • 15,791
  • 4
  • 36
  • 68
user1688928
  • 21
  • 1
  • 5
  • 3
    Maybe because you have `AllowOverride None` set in apache configuration, and your .htaccess is not being parsed at all? – dkasipovic Apr 14 '14 at 13:53
  • Thanks for the reply DKasipovic, I will have a look in a bit. I think it might be though because it is finding the 404 page... Thanks – user1688928 Apr 14 '14 at 14:01
  • 2
    I also suggest another solution, just find a way to link to php files. Html files don't excecute php for a reason ;) – Martijn Apr 14 '14 at 14:08
  • Yea, I think it's nasty too. But just got hosting for a site that isn't mine, and this is how has been coded :/ – user1688928 Apr 14 '14 at 14:13
  • `AllowOverride All` is the current method set. Im a bit stumped by this one? @DKasipovic @Martijn – user1688928 Apr 14 '14 at 14:47

1 Answers1

0

Since your server will not allow you to use PHP in HTML, just rewrite all .html requests to php in :

RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]

Should solve the problem. (https://stackoverflow.com/a/5990276/2119863)

Why won't it parse PHP in HTML?

The more types of files the server needs to push through the php interpreter, the more memory, processor and electricity it will consume. It's like with cars and trucks. Cars do not haul big trailors for a reason - trucks have much bigger engines and take the load but leave a bigger carbon footprint.

The second reason is the separation of functionalities. Seeing a html file, you should be 100% confident - across all and any servers - that this file will not print_r($_SERVER);. And when seeing a php file, you should be confident it performs some dynamic actions. And just like you shouldn't expect a nurse to build houses, neither should you expect HTML to parse PHP. :)

Community
  • 1
  • 1
Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51
  • Thanks for your suggestion, unfortunately this throws 404 errors saying that index.php does not exist. I would change all the pages to PHP if it were my site, but it's not - i'm just hosting it :( – user1688928 Apr 15 '14 at 11:06