Writing SVG and MathML for PHP on Apache

I am a little confused about how to set up the Apache server. I am using Apache 2.2.11

Take these 2 pages as a good example:

HTML XHTML

They both are 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

      

This is how MathML and SVG are displayed.

Most websites now work with PHP anyway. I installed this in my Apache:

AddType application/x-httpd-php .php

      

Standard syntax and that's it.

But if I want PHP pages to render MathML and SVG, I think I need to do this:

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

      

But that doesn't work, PHP doesn't parse anymore.

So how can I make sure PHP is still working fine and at the same time I can use things like MathML and SVG in combination?

0


a source to share


2 answers


If you have a PHP script that outputs something other than HTML, you just need to set the content type HTTP header from the script.

for example, if you have a script called xml.php that outputs XML, it must include a line like:



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

      

No Apache configuration required.

+4


a source


The directive controls how .php files are processed on the server. The file is passed to a program or module configured to handle type application / x-httpd-php due to the appropriate or , for example: AddType

Action

AddHandler

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

      



(That is, unless you are using the original PHP source file, raw. I doubt you want to do this.)

Keep your configuration as before. Use header

to set a different Content-Type header for the script output, as Frank's answer demonstrates.

0


a source