Run .html file as php

nobaloney

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
25,333
Location
California
I'm not a php guy so please bear with me.

One of my clients wants to parse .html files for .php.

I've tried this the so-called right way that I see on the 'net. I've tried this the DirectAdmin way by adding a handler, both at the admin level and at the user level.

It doesn't work.

System is running php5 as cgi (suPHP).

Any ideas how to do this? Preferably something you know works :).

Thanks.

Jeff
 
You can do it with .htaccess

Code:
<FilesMatch "\.(html|htm)$">
RemoveHandler .html .htm
AddHandler x-httpd-php5 .html .htm
</FilesMatch>

The x-httpd-php5 should match the handler name in /etc/httpd/conf/httpd-suphp.conf

This line:

Code:
suPHP_AddHandler x-httpd-php5
 
Last edited:
I'm not a php guy so please bear with me.

One of my clients wants to parse .html files for .php.

I've tried this the so-called right way that I see on the 'net. I've tried this the DirectAdmin way by adding a handler, both at the admin level and at the user level.

It doesn't work.

System is running php5 as cgi (suPHP).

Any ideas how to do this? Preferably something you know works :).

Thanks.

Jeff

I thought this was one of the drawbacks of running php as cgi, you could not have php embedded in html code.

Let us know if scsi's solution works. If it does I might be convinced to switch.
 
@scsi,

Unfortunately it's still not working :(.

Any ideas as to why it may not be, or where else I should look?

Thanks!

Jeff
 
I thought this was one of the drawbacks of running php as cgi, you could not have php embedded in html code.

Let us know if scsi's solution works. If it does I might be convinced to switch.
It didn't work. Can you point me somewhere that says it doesn't work? I can't find anything and would love to show this to the client.

Thanks.

Jeff
 
I am not a php person. I am a perl person. I know when setting up apache to run a perl cgi script the configuration is based on the extension such as .cgi or .pl. However you can use any extension as long as the path to perl is at the top (#!/usr/bin/perl) and everything in the file uses perl code.

I would assume the same is true of php since cgi is not a language but a way of communicating. I do know that the php scripts that run as cgi have to have to have the path to php (#!/usr/bin/php) just like a perl script does.

So you probably could have .html run as a cgi but it would have to be in the programming language of choice whether perl or php. I know perl has a way of inserting pure html within the script. Php probably has something similar. But this would be inserting html code in a script not php code in html.

I have done minimal googling on this and have not been able to confirm either way.

If somebody can tell me where I am wrong on this I would be happy to hear it.
 
Seems weird it wouldnt...I run html as a php extension globally by adding it to the file extensions in /etc/httpd/conf/httpd-suphp.conf

Oh I just tested it....

This works:

Code:
<FilesMatch "\.(html|htm)$">
AddType x-httpd-php5 .html .htm
AddHandler x-httpd-php5 .html .htm
</FilesMatch>

Must have needed the addtype line...
 
Last edited:
Back
Top