≡ Menu

Run PHP with html extension

php using html extension

I know a lot of my readers may already know this but I get asked this question about how to run php with an html extension enough that I thought I would get it down in print so I can just send people to it.

I often get the question “How do I use php without changing my url’s?” or “How do I just make one header and footer file to include in each page so I only have to change them once when a change is needed?”.

Some people want to start using some server side programming but don’t want to lose the pages they already have indexed and ranking in the search engine. Some just like to have pages that look like page.html instead of page.php. Some people think they have to change their extensions to .shtml to use includes.

All you have to do is add one line to your .htaccss file. You won’t have one of those if you are running IIS. I’m not sure how to do this on IIS. If you don’t have a .htaccess file then you can just create one. First on your computer create a text file called htaccess without any extension. Put:

AddType application/x-httpd-php .html

in that file.

What this does is tell the server to treat files with the .html extensions as if they had the .php extension. Now you can use php includes ( ). One downside to doing this is that all files will be ran through the php parser. This should not be a big deal since you are putting php in all your pages anyhow for the header and footer.

php using html extension

{ 2 comments… add one }

  • beauty January 25, 2008, 10:57 am

    I think it looks a lot cleaner to come up with a nice mod rewrite system that completely removes file extensions and interprets the query string. looks a lot neater.

  • Michael March 23, 2011, 4:32 pm

    I fail to see how using pagename.php.html is going to help Google index pages that were called pagename.html Google is still going to show bad links for all the pages you used to call pagename.html and take its time in indexing the new pages anyway. What is the advantage?

Leave a Comment