tags:

views:

931

answers:

3

I have an odd problem...I'm using a documentation generator which generates a lot of output like docs/foo.php.html. It's XHTML, and thus contains <?xml...> tags at the beginning of file. The problem is, Apache has somehow decided to run it through the PHP interpreter, even though ".php" appears in the middle of the filename, and not at the end. This in turn triggers a PHP error, because it sees "<?" as the command to start executing PHP code, and immediately gets confused by the "xml..." which follows it.

How do I configure Apache to ONLY execute .php files, and not .php.html files? The string "php.html" does not appear explicitly anywhere in my Apache config files. There is a line "AddHandler php5-script .php", but I don't see how that would also include ".php.html" files.

+3  A: 

You could disable PHP's shorttags -- this is the recommended way to mix PHP and XML.

http://us.php.net/ini.core

short_open_tag = 0
John Millikin
What he said. Be sure to check your code, though.
analytik
Unfortunately I think there are a handful of places that use things like <?=$foo?> which needs short tags :(
davr
Yes .. but. If you do that, the xml files will work, but they'll be served far slower than they should be, because they have to pass through the php interpreter (which will also add all the standard php no-cache headers). Not a good plan.
TRiG
A: 

Are .html files listed as being allowed to be parsed as PHP? I've seen some shared hosts set .html files to be usable as a valid PHP extension which may also be catching your .php.html files.

dragonmantank
That's what I thought at first, but if I make a file 'test.html', PHP code will not be executed in it. If i make a file 'test.php.html', PHP code WILL be executed in it.
davr
+5  A: 

The problem seems to be in mod_mime.

Quote from the Apache mod_mime documentation page:

If you would prefer only the last dot-separated part of the filename to be mapped to a particular piece of meta-data, then do not use the Add* directives. For example, if you wish to have the file foo.html.cgi processed as a CGI script, but not the file bar.cgi.html, then instead of using AddHandler cgi-script .cgi, use

<FilesMatch \.cgi$>

SetHandler cgi-script

</FilesMatch>

Also, you can google for apache mod_mime "multiple extensions"

alexandrul
This fixed it, thanks! Probably would be ideal if I could just eliminate short tags, but can't do that in this case.
davr
Wow I had no idea Apache did this - surely it could be a big security problem (if you weren't aware of this and you did something like naming files filename.php.txt thinking that would prevent them being interpreted).
thomasrutter