To be able to use php code on a page with an extension other than .php, you need a server which supports .htaccess files.

To add an extension to be parsed for php, create or edit a file called .htaccess (with the dot first) containing the following line:
AddType application/x-httpd-php .html .moo .htm
This tells the server to check for php code and execute it in files with extensions .html, .moo or .htm. So upload that .htaccess file in the same folder as your .html files with PHP code inside them (using PHP tags: <?php ... ?>) then when you view them in the browser, the PHP should be dealt with as you’d expect from a PHP page.


5 Responses to “How to use PHP in pages with a .html extension (or any other)”  

  1. Gravatar Icon 1 Jeremy Votaw

    Why would you want to do this?

  2. Gravatar Icon 2 Moin

    great! & greatest infromation. thanks.

  3. Gravatar Icon 3 V anesa

    I have good page ranking however I wanted to use php on the pages without resorting to making it a page with php extension. It really works…is there a downside though?

  4. Gravatar Icon 4 Eric

    You can do something similar with mod rewriting, though it is more complicated. The whole idea behind making php “appear” like static html is, generally, for search engine optimization reasons. Many search engines do not like dynamically generated content, leading some webmasters to “trick” search engines by making them think that dynamic php pages are really static html.

  5. Gravatar Icon 5 James

    I think a more important reason is so that if you ever switch to a different server-side scripting language, you don’t have to break all existing links.

Leave a Reply

You must log in to post a comment.


Categories

Related Entries

  • No related posts.