Parsing .html as php

I have installed apache2 php5 on opensuse 11
I wish to parse .html files as php. I used to do this with .htaccess and addtype, however this does not seem to work with apache2

Anyone got any ideas on this?

Why not just rename the file to end with .php instead of doing it the hard way.

I am not quite sure on what you are trying to do here. if you were to parse html as php, it would just be translated back into HTML…

can you give us a code example of what you were doing before?

I think the OP wants to execute some PHP inside his HTML files. IMO if the file contains PHP code, it should be given an extension of .php.

ah okay. You cannot execute PHP code inside an html file. Apache uses the extension of the file to determine how a file is processed. If PHP is being processed inside of an html file, it is more likely that the server is setup to display the php script as an HTML file. I don’t remember the exact module that does this…

Yes, I want to parse some php which is inside an .html file. I realise this is somewhat unusual and probably I should use a .php extension. However, I have loads of existing websites I’d like to do minor updates to which have php inside the .html files. I developed them under php4/apache and parsing .html files as though they were php was simple… Apache2 is another story…

Try editing /etc/apache2/conf.d/php5.conf

But make sure normal .php files work first or you will be chasing red herrings.

Hey Ken_yap, I’ve added
AddHandler application/x-httpd-php .html
to php5.conf but no luck there. php is parsing fine with .php extension.

Works for me. I created the file /srv/www/htdocs/test.html

<?php
phpinfo();
?>
Some text

Added the line:

AddHandler application/x-httpd-php .html

to /etc/apache2/conf.d/php5.conf, reloaded apache2, then navigated to http://localhost/test.html and got the usual PHP config info, plus the line Some text at the bottom.

arrrgh,
caught out by php4 syntax again. Man, php5/apache2 is taking awhile to get used to. All my old sites have <? as opening brackets instead of <?php, and so obviously php5 was not parsing the code with the brackets, giving the appearance that it was not parsing because of the extension.
Thanks Ken, your trick worked a dream :slight_smile:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

s/<? /<?php /g

I never understood why the “short” version was ever used… ‘php’ is
about the fastest thing in the world to type… oh well.

Good luck.

truenz wrote:
| arrrgh,
| caught out by php4 syntax again. Man, php5/apache2 is taking awhile to
| get used to. All my old sites have <? as opening brackets instead of
| <?php, and so obviously php5 was not parsing the code with the
| brackets, giving the appearance that it was not parsing because of the
| extension.
| Thanks Ken, your trick worked a dream :slight_smile:
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFInFhq3s42bA80+9kRAoImAJ95qHxVqW1X5Td3m41XcDcfilJ3WQCeMRuy
htSVdIjtisD7chncRVAQGQs=
=kYPp
-----END PGP SIGNATURE-----