Jump to content

using .htaccess to parse php in .html files


mojito

Recommended Posts

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?

[code]AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .php3[/code]
Link to comment
Share on other sites

ratther then doing the following: [code]AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .php3[/code]in you .htaccess do it one line like so:
[code]AddType application/x-httpd-php .html .htm .php3 .phtml[/code]
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).
Link to comment
Share on other sites

  • 3 months later...
[quote author=mojito link=topic=89632.msg359675#msg359675 date=1143645237]
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...
[/quote]
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.
TecBrat.
[code]AddType application/x-httpd-php .html .htm .php3 .phtml[/code] 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
Link to comment
Share on other sites

  • 2 weeks later...
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:

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

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:
http://www.littlegreentoaster.com/testdir/

To see the HTML file without the PHP parsed:
http://www.littlegreentoaster.com/testdir/index.html

And to validate that PHP is installed and working
http://www.littlegreentoaster.com/testdir/index2.php

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

-adam
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.