1

I'm working on an old site, and I want to add cookie functionality in order to allow people to use the mobile site, but also opt-into using the full site if they want. The site is currently all .htm files, and I can't with the budget go in and change every link to .php so I tried adding this to my .htaccess file

AddType application/x-httpd-php .htm

This is causing the browser I'm using (Firefox) to ask me to download the file. It says it's a application/x-httpd-php file, so I know the .htaccess file is working. When I was building my home web sever, and trying to run a ruby on rails site I ran into the same problem because i hadn't set up ruby correctly and it wasn't rendering the file. But I have never run into a site that doesn't have some sort of support for PHP. Could this be caused by another problem. Or does that .htaccess file change break rules made by some web hosts?

Any support would be amazing! Thank you so much everyone :)

Chris Frank
  • 4,124
  • 4
  • 30
  • 42
  • Is php module loaded by your httpd server ? – Armage Sep 27 '13 at 16:50
  • I'm almost certain it is, we are running a mailing script which uses php v4. I also tried setting the .htm files to use v4 and that didn't fix the problem. – Chris Frank Sep 27 '13 at 16:51
  • @ChrisFrank Potentially a silly question but I'll ask it anyway. Does the server (in question) in fact offer PHP support? To test, create a file called "test.php" and put this inside and run it `` – Funk Forty Niner Sep 27 '13 at 16:51
  • @Fred-ii- Yes, I just did that, and the phpinfo page came up. I looked through it and it didn't seem to be off in any way – Chris Frank Sep 27 '13 at 16:54
  • @ChrisFrank Have a look at this page, it may be of help http://deano.me/2013/06/running-php-in-htmhtml-files-using-htaccess-troubleshooting/ – Funk Forty Niner Sep 27 '13 at 16:55
  • There's also the "php_admin_value engine Off" line I found some time on apache config file... – Armage Sep 27 '13 at 16:57
  • @ChrisFrank See Q&A's here too http://stackoverflow.com/questions/6295141/server-not-parsing-html-as-php and Google `AddType application/x-httpd-php .htm php 4` – Funk Forty Niner Sep 27 '13 at 16:58
  • 1
    @ChrisFrank As Jon Lin states in his answer, it's `AddHandler application/x-httpd-php .htm` - try that out, am sure it's going to work now. – Funk Forty Niner Sep 27 '13 at 17:08

1 Answers1

2

You need to add a handler for that type, otherwise the webserver isn't going to do anything with it:

AddHandler application/x-httpd-php .htm

That should be enough if you've already got phpv4 executing on your server. But you can also create a custom action explicitly:

AddHandler application/php-cgi .htm
Action application/php-cgi /path/to/php-handler 
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Sorry if this sounds like a completely stupid question, I've never had to convert .htm files to php, when I tried to add php code into the file it's loading the file, but not executing the php, when I view source in FF, it's giving me an error, 'Attempt to use XML processing instruction in HTML' – Chris Frank Sep 27 '13 at 17:13
  • 1
    @ChrisFrank Your HTML files probably have some DTD at the top (e.g. ` `) which is describing exactly what kind of schema is being used, and that's not jiving with what FF thinks it is. – Jon Lin Sep 27 '13 at 17:15