tags:

views:

353

answers:

2

I'm a little confused as to how to configure my Apache server. I'm using Apache 2.2.11

Take these 2 pages as a good example:

HTML XHTML

They're both one and the same syntax, but the extension is different. The first file has HTML as an extension, the second has XHTML as an extension.

The server in the background has the following set:

AddType application/xhtml+xml .xhtml

By doing so, the MathML and SVG are correctly displayed.

Now, most websites work with PHP anyway. I've set this in my Apache:

AddType application/x-httpd-php .php

The standard syntax and all.

But if I want my PHP pages to display MathML and SVG too, I'm thinking I need to do this:

AddType application/xhtml+xml .php
AddType application/x-httpd-php .php

But that doesn't work, PHP no longer parses.

So, how can I make sure PHP still works like normal and at the same time I can use things like MathML and SVG in combination?

+4  A: 

If you have a PHP script outputting something other than HTML, you simply need to set the content-type HTTP header from within your script.

e.g., if you have a script called xml.php that outputs XML, it should include a line like:

<?php header('Content-type: application/xhtml+xml'); ?>

No apache configuration is necessary.

Frank Farmer
A: 

The AddType directive controls how .php files get handled on the server. The file gets passed to the program or module configured to handle the application/x-httpd-php type due to a corresponding Action or AddHandler directive such as this:

Action application/x-httpd-php "/php/php-cgi.exe"

(That is, unless you're serving the PHP source file itself, unprocessed. I doubt you want to do that, though.)

Keep your configuration the way it was before. Use the header function to set a different Content-Type header for your script's output, as Frank's answer demonstrates.

Rob Kennedy