Recently I wanted to use PHP includes in an existing site so I could make updates to common parts of the site faster by editing one file (e.g.: header, navigation, footer, etc.). The problem was the site was designed with all pages ending in .html. Of coarse I could have changed all the pages to .php but the site has very good search engine rankings, and many other sites already link to these .html pages. After a little research, I found the solution to be the .htaccess file.

Since pages without a .php-extension will not be parsed by PHP by default on most web servers, you need to tell it to treat all HTML pages as PHP pages. You do this by simply adding a line to the .htaccess file located in your site’s root directory (or create a .htaccess file using a text editor). Just add:

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

Note: .htaccess files need to be placed in each directory that will make use of PHP in .html pages.

Update: If you get an 500 Internal Server Error try “AddHandler application/x-httpd-php .php .html .htm”

It is good to share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Categories: PHP ~ No Tags ~ Trackback

One Response to “Using PHP on Pages with HTML Extensions”

  1. 1
    srikanta

    i want to add header and footer to every web pages

.htaccess accessibility Apple articles browser bugs chrome CSS domain names ecommerce email ems eps fonts google HTML http https IE Internet Explorer interview Mac menu PayPal plugins redirects Safari SEO spam SSL survey tools web standards website design Windows WordPress