Home > Misc, SEO, Tutorials > Run PHP with html extension

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

Categories: Misc, SEO, Tutorials Tags:
  1. January 25th, 2008 at 10:57 | #1

    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.

  2. May 15th, 2009 at 00:32 | #2

    This is a bit off topic, but talk about getting scared about losing all of your indexed page, I customized my permalinks on my WordPress Blog and it messed everything up for a few months. I had 0 out of 200 pages indexed and tons of errors in my sitemap even though I resubmitted my xml sitemap with the urls updated. Every week Google indexed about 30 pages or so and finally all 200 were indexed! http://www.robbuti.com/.

  1. No trackbacks yet.