View Full Version : mod_perl: Running XML through PHP preprocessor

Alex Vincent
07-13-2003, 05:25 AM
Lately I've been revisiting an old thorn in my side for HTTP usage. Namely, how can I pass to PHP, SSI, Perl, or Python (or any other language as needed) an XML document for processing via XML processing instructions?

At first, I tinkered with the idea of creating custom Apache filename extensions (.pxml, for instance, for PHP-processed XML). A little work with .htaccess showed that wouldn't necessarily fit the bill.

So I'm exploring another idea, based on something I remember Firepages telling me.

Suppose I have a URI:


Where the actual file resides at

The "php" directory could be an alias for indicating I should send the document through the PHP interpreter. After it goes through the interpreter, the server would then return the correct mime-type.

Is this doable, perhaps with a couple sub-requests, perhaps an HTTP HEAD request involved?

UPDATE: Figured out how to do the PHP thing, at least for phpdev4.2.3. In httpd.conf, add the following:

# run PHP interpreter through a directory request
Alias /processPHP/ "C:/phpdev/contentTypes/process.php/"
<Directory "C:/phpdev/contentTypes/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from localhost

php.ini gets its "short_open_tags" value set to "Off", so I don't have to worry about <?xml version="1.0" ?> triggering PHP...

Then I create a new directory, C:/phpdev/contentTypes/, and I add the following files:


AddType application/xhtml+xml .xhtml
AddType image/svg+xml .svg


$fileInfo = apache_lookup_uri($_SERVER["PATH_INFO"]);
header("Content-type: ".$fileInfo["content_type"]);

Now I need to figure out equivalents for Perl and Python...