Website Design Blog of Alfred Fox

May  0714

Using PHP Code In Your HTML Files

Using PHP Code In Your HTML Files
Posted in .htaccess

I have this habit of not using .php files if at all possible. It's nothing personal, I simply prefer .html. Whether its more SEO friendly or not is left up to personal opinion and I simply don't have an answer that will agree with the vox populi (as there are very strong opinions on each side). However I do know this, there are a plethora of posts, blogs, and websites touching on this subject. So I figured I'd not only put in my two cents, but also show you how to do this.

So here's the tutorial to add PHP functionality to your HTML pages. (Running PHP code in .html files). To do this you need to be able to modify and use a .htaccess file. If you don't have one and are using an Apache server simply create one in your root web directory. You can speak with your hosting provider for more information on this.

Add these lines to your .htaccess file.

AddType application/x-httpd-php .html

That's it. Now you can run php code in your .html files. Pretty simple.

So my two cents, basically, I guess I don't have anything to add except I prefer .html files to .php as I've stated. There's nothing wrong with .php files, but a lot of clients I've worked with in the past have specifically requested I not use .php. It can go either way though, .php is easily picked up by search engines just as .html. To each his own in this case.

AddThis Social Bookmark Button

Back

Leave a comment

Cancel

Name

Email Required but kept private.

Website e.g. - http://www.yoursite.com

Comment

Are You Human? Please enter the text as you see it in the image below

Comments for Using PHP Code In Your HTML Files

Increase Search Engine Ranking - 2/17/2008
I agree. We have both options. What I have found is that it's just easier to do a redirect. But I believe SEO is better served by .html, or .htm

Just my $1.50
Harry Roberts - 6/24/2008
Really? As easy as that?!
Web Designer - 6/30/2008
I dont know this! I thought you cannot use PHP code on HTML. This is very useful.. Thanks!