Jump to content


using .htaccess to parse php in .html files

  • Please log in to reply
4 replies to this topic

#1 mojito

  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 29 March 2006 - 03:13 PM

Using the code in a htaccess file one can specify that any file extension be treated as if it were a php file.

I wonder why this is done, for me it makes a dependancy situation arise that if the htaccess is not there then the code is output to the browser and a security risk. Ok so we can be careful but is it a SEO thing?

do .php pages get a worse treatment from spiders?

what other considerations..

here is the content of the .htaccess for complettness-would this replicate in child folders or does this file need to be in child folders too?

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

#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 March 2006 - 03:46 PM

ratther then doing the following:
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .php3
in you .htaccess do it one line like so:
AddType application/x-httpd-php .html .htm .php3 .phtml
just seperate each file extension by a space!
You dont have to put .htaccess file in every folder. However you can just place it one folder and it'll effect everysingle folder that is below it. Such as the root folder (wwwroot, public_html, public_www or whatever your root folder is called).

#3 ober

  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 29 March 2006 - 03:48 PM

Keep in mind that some people are forced to do this if they don't have access to the web server configuration files.

Info: PHP Manual

#4 TecBrat

  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 16 July 2006 - 02:03 AM

Using the code in a htaccess file one can specify that any file extension be treated as if it were a php file.
I wonder why this is done...

Thanks for the info, and I'll give my answer to your wonder.  We will occasionally take over a website that has already established itself with html files. If I go changing them to php files, who knows what references might get messed up (Internally, or from 3rd party links)? Now I will be able to customize those pages with my code, but not re-name them.
AddType application/x-httpd-php .html .htm .php3 .phtml
This worked for me.

pardon a bit of keyword stuffing, but people might need help finding this thread:
parse php inside html, read php in html files, treat html like php. extensions
It's kinda lame at the moment, but...
PHP MySQL Playground

#5 snailface

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 26 July 2006 - 01:06 PM

Does anyone know of a situation where modifying the htaccess file (or adding one to a specific directory within a hosting account) would cause the following behavior?

I added an htaccess file consiting only of the line to a directroy where I would like .html files to be parsed for PHP:

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

But now, when I navigate to that directory (without specifying a file so that it should default to index) I get prompted to open or save a file.

If I navigate specifically to the file, it is displayed in the browser, but without the PHP having been parsed.

To see what I am talking about I put up some sample files.
To see the wierd file download behavior go to:

To see the HTML file without the PHP parsed:

And to validate that PHP is installed and working

Thanks in advance to anyone who can shed some light on this for me.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users