scriptygoddess

02 Apr, 2003

Running PHP on a html or htm page

Posted by: Jennifer In: How to's

I've had to look this up more times than I can count. I think I've made a post to link to it, but it'd be easier for me if this was just here. I got this code from Christine who posted it on the Blogomania support forums ages ago. (side note: Those forums are mostly for people who are hosted on Blogomania – but obviously you're free to peruse the info there)

To make your .htm or .html pages process like they were .php, just add this line to your .htaccess file:

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

15 Responses to "Running PHP on a html or htm page"

1 | Jasmeet

April 2nd, 2003 at 10:08 pm

Avatar

Heh, I could've used this bit of knowledge a few moanths ago. Oh well =)

2 | jason

April 3rd, 2003 at 2:20 pm

Avatar

I've used this little piece of info myself in the past. I've downloaded some PHP programs where the extension of the scripts are all .php3. By just adding another type to the list, it saves you from having to rename all the scripts to the correct extension.

3 | Amy

April 4th, 2003 at 11:10 am

Avatar

Well, something should be mentioned here about choosing wisely. Let's say that you choose to have all .html pages php-parsed. While the slowdown won't be much per page, the pages WILL take a bit more time to load. You should weigh the slight slowdown on all pages against the value you get from this change. If you're going to slow down quite a few pages for the benefit of just a couple, you're probably better off converting those few pages to .php and leaving the others untouched.

4 | Christine

April 6th, 2003 at 11:46 pm

Avatar

Also, some servers parse .html and .htm pages automatically – that was why, when I first skinned my site using Amy's instructions, I never realized the pages needed to be named .php. When I moved my site last April to where Blogomania now lives, everything broke and that was the fastest fix.

Someday I might see if I can rename everything .php – but then again, that would mess up everyone's links and so forth – so I guess those few seconds are just it for right now…

5 | Andy

May 2nd, 2003 at 4:08 pm

Avatar

Or use:

RewriteEngine On
RewriteRule ^index.html /index.php

Inside your .htaccess file.

An excellent way of parsing PHP as HTML or .whatever so an overhaul of your site and URL rewriting in your .htaccess file will keep all your links the same. Sure to have some drawback along the way, maybe load speed and so on but then Apache isn't perfect as it's not made me a cuppa yet 😉

6 | Katia

August 9th, 2003 at 2:32 pm

Avatar

I'm coming into this very late indeed, but am relieved to find this little gem :) Thanks for sharing it :)

Having recently skun my blog (skun? is that a word? hehe), I am interested in the actual functionality behind this… I assume that this searches for all instances of htm html and php, and just goes to the one that is there?

My blog is on a site with other blogs, so changing the htaccess file so that my php pages will be brought up when people type index.html, won't affect the other pages who use index.html?

7 | Jennifer

August 10th, 2003 at 10:17 pm

Avatar

Katia – when you change an .htaccess file, it will affect that directory and any and all within that directory. If the other people who share your hosting space are within the directory where your edited .htaccess file resides – then they will be affected too. If they are in a seperate directory path – then they shouldn't be affected.

8 | Katia

August 11th, 2003 at 11:29 am

Avatar

Ok, that's brilliant – exactly what I needed to know :) Thanks Jennifer :)

9 | Laura

October 14th, 2003 at 2:19 am

Avatar

If you are running PHP with Microsoft IIS Go to Internet Information Service MMC snapin, Right click on Default Website, Properties, Documents Tab, add Default.php in the enabled default documents list and move it to the top of the list.

10 | Nick Queen

January 10th, 2004 at 3:45 pm

Avatar

Where is .htaccess found?

Stupid question I know!

11 | Jennifer

January 10th, 2004 at 3:52 pm

Avatar

It is a file that would be found (or can be placed) inside any directory on your server. If you're using an FTP client to look for it – make sure that it will even SHOW YOU those files. Some FTP clients have a special setting that you need to change in order for it to display files that begin with a "." – To be honest – in any FTP application I've ever had – I've NEVER been able to find that setting!! I usually use my host provider's "file manager" through "cpanel" to navigate to and edit those files.

12 | Jennifer

May 5th, 2004 at 1:44 pm

Avatar

just a slight modification to this comment I left here – I believe that if a sub directory below where you have your .htaccess file is accessed via an alternate URL (ie a different URL/domain that points specically to that SUBDIRECTORY) – then the settings in that outside .htaccess WILL NOT affect those pages! I'm not sure if the same occurs when the it's a SUBDOMAIN – as opposed – ie. subdomain.maindomain.com

13 | Bloggins

April 2nd, 2003 at 11:24 pm

Avatar

PHP on HTML
Ever needed to make a .htm or .html page act like a .php page? Maybe you have some php code…

14 | scriptygoddess

October 19th, 2004 at 4:39 pm

Avatar

[…] n image file. Hang in there) Then, in the htaccess file for JUST THAT FOLDER! (similar to this trick) I added this: AddType application/x-httpd-php .p […]

15 | Ryan

October 21st, 2004 at 2:33 am

Avatar

I know I'm replying to a rather old post, but since FTP clients have driven me nuts with their inability to show "." files I thought I'd mention my FTP Client of choice (which has the setting you refer to). FileZilla! It's great. Check it out.

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements