web hosting reviews


Make PHP to work in your HTML files with .htacess

Web Hosting Articles \ A simple guide to .htaccess \ Make PHP to work in your HTML files with .htacess


By default most web servers across the internet are configured to treat as PHP files only files that end with .php. In case you need to have your HTML files parsed as PHP (e.g .html) or even if you want to take it further and make your PHP files look like ASP, you can do the following:

For web servers using PHP as apache module:

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

For web servers running PHP as CGI:

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

In case you wish to do the ASP mimick:

For PHP as module:

AddType application/x-httpd-php .asp

OR

For PHP as CGI:

AddHandler application/x-httpd-php .asp

  1. How to block users from accessing your site based on their IP address
  2. How to prevent or allow directory listing?
  3. How to change the error documents – 404 Page Not Found, etc
  4. Using .htaccess for password protecting your folders
  5. Using .htaccess to block referrer spam
  6. Disable Hot-Linking of images and other files
  7. Redirect URLs using .htaccess
  8. Introduction to mod_rewrite and some basic examples
  9. Force SSL/https using .htaccess and mod_rewrite
  10. 301 Permanent redirects for parked domain names
  11. Enable CGI, SSI with .htaccess
  12. How to add Mime-Types using .htaccess
  13. Change default directory page
  14. Block Bad robots, spiders, crawlers and harvesters
  15. Make PHP to work in your HTML files with .htacess
  16. Change PHP variables using .htaccess
  17. HTTP Authentication with PHP running as CGI/SuExec
  18. Force www vs non-www to avoid duplicate content on Google
  19. Duplicate content fix index.html vs / (slash only)

Comments 13 >>

Adi Said,
Oct 05, 2006 @ 14:15

Thank a lot! This was really helpful.

I am using a hosting service at hostgator and there

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

seems to work.

Truly
Aditya
www.adiwebs.com
Jamie Said,
Oct 14, 2006 @ 09:48

Bit Pointless, as it's security by obscurity. Which always ends up not being worthwhile.
Vince Said,
Oct 14, 2006 @ 10:53

It is not all about security :)

There are many other uses of making your PHP files look like HTML pages.

Take SEO for example.
Jon Said,
Nov 10, 2006 @ 06:21

Hi

I am planning to use php includes to rebuild my pages. Currently all my pages are .html
One suggestion was to change to .php but this will cause all links to break, including all important search listings.
Is placing this code in the htaccess file my solution ? i.e. I do not need to change the names of the files?
AddHandler application/x-httpd-php .html .htm

My tech skills are pretty low, so looking for a simple solution. I do not have access to the Apache thing on my server (which a friend suggested).

Cheers

Jon.
vince Said,
Nov 10, 2006 @ 17:55

Yes, Jon

This should work fine for you.

However, whether you should use AddHandler or AddType depends on how your PHP is configured.

May be it would be best to consult your web hosting company about their particular setup.
Jon Said,
Nov 13, 2006 @ 05:42

I contacted 1and1, still waiting for some advice. I have now tried the following, and all have failed:

AddType application/x-httpd-php .htm .html
-- results in attempted download

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
- results in attempted download

AddType x-httpd-php .php .htm .html
AddHandler application/x-httpd-php .php .htm .html
-- prevents php being read in php file (e.g. http://www.tranquillizer.co.uk/supplement-whey-protein.php)
and does nothing for .html file (e.g. http://www.tranquillizer.co.uk/phptest.html)

Do .php pages rank any differently from .html? Maybe I will go the route of renaming all pages to .php and setting up redirects. It probably will not be much more work to start with.

Do you know about mod re-writes? I came across this somewhere, but am not sure if that will help either! Still so much to learn.

Cheers,

Jon.
vince Said,
Nov 16, 2006 @ 16:55

You will need to ask 1and1 about their particular setup.

No, PHP files do not rank different, however if you already have your HTML files indexed it will be easier for you to add some interacitivity or dynamic content generation without losing your SE rankings.
E Said,
Mar 25, 2007 @ 21:13

Yes I have the same problem with 1and1. I contacted them but they will not help. Basically their responce was that I need to learn scripting, but they won't tell which kind. This is really awful responce especially that they are doing advertisement on OUR domains that we PAY for. I think a class action suit is called for!

Meanwhile I whish there was a solution to this problem.
Dennis Said,
Jul 12, 2007 @ 11:14

Hey Jon & E

I had the same problem but finally found the solution:
AddType x-mapp-php4 .html .htm

Found here: http://faq.1and1.com/scripting_languages_supported/configuring_apache_server_using_htaccess/4.html
Kimber Said,
Jul 20, 2007 @ 07:49

I have alway used this method with very little problem but recently have been getting error message. I get a lot of error but it comes down to (include_path='.:/usr/lib/php:/usr/local/lib/php')


Any idea why?
Thanks
bailey Said,
Nov 05, 2007 @ 09:45

As for web hosting companies, if you want someone to hold your hand do not go for discount hosting like 1and1 or go daddy or any of cheap hosting companies. You either spend money for tech support to teach you or your time to learn how.
Sorry, if this bothers people but how exactly is a hosting company going to afford people and the time to walk you through apache mod rewrites for a few bucks a year.
Now that I got that off my chest, 1and1 and most shared hosting companies run php in cgi mode for performance reasons.

Love this site.
johnrobin Said,
Feb 05, 2008 @ 04:44

are there any security issues with this setting? I'm trying to test some php file for this..
Andre Said,
Jul 01, 2008 @ 12:56

AddType x-mapp-php4 .html .htm

Will that run on PHP 4 only?
Your comments on this article

(required)

(required but never displayed)



security code



Previous: Block Bad robots, spiders, crawlers and harvesters Next: Change PHP variables using .htaccess

Back to Web Hosting Articles list

Web hosting companies A-Z:
All web hosting companies


About - Terms of Use - Privacy Policy -
Web Hosting Reviews