Parsing PHP on .html pages

Filed under: htaccess, PHP

There are 2 ways of getting your .html pages to parse PHP, this is via:

  1. .htaccess
  2. httpd.conf

In both methods above, you need to make sure that your server supports PHP.

Which method to choose?

For most webmasters who uses shared hosting and do not have access to their server’s configuration files, you would use method one, via .htaccess. If you have access to your server’s configuration files, that is, you have a dedicated server and can access httpd.conf, then use method two, via httpd.conf.


1. Via .htaccess

  1. Create a .htaccess file or open your existing .htaccess file in your root directory.
  2. Add the following line to your .htaccess file:

    AddType application/x-httpd-php .html

  3. Save your .htaccess file and upload to the root directory of your web site.

Your .html page will now parse PHP.

2. Via httpd.conf

  1. For Linux servers using Apache, find a file called httpd.conf. This file should be in the folder called, “conf” in the Apache program files. It may be on the server as:

    /etc/httpd/conf/httpd.conf

  2. In httpd.conf, find the line that looks like this:

    AddType application/x-httpd-php .php

  3. Add the following line below:

    AddType application/x-httpd-php .html

    Or alter the AddType application/x-httpd-php .php to:

    AddType application/x-httpd-php .php .html

  4. After making these changes, restart your web server. For unix based servers, using this command:

    service httpd restart

Your .html pages will now parse PHP.

divider

2 Comments to “Parsing PHP on .html pages”

  1. martina Says:

    I like this site very much!

  2. Chris Says:

    This is very interesting but the .htaccess AddType etc kills off the parsing of html on my sites and the additions to the httpd.conf make no discernable difference.
    These sites are on unix servers and my ISP is apparently not up to speed on these tweaks.

    Excellent site.
    Please keep up the good work.

Leave a Comment