HTACCESS for PHP processing in HTM files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
RacerX
Forum Newbie
Posts: 21
Joined: Tue Jul 01, 2003 9:21 am
Location: NorthEast USA

HTACCESS for PHP processing in HTM files

Post by RacerX »

Does anyone know of the script that allows .htm files to have PHP processing? I know you add something to the .htaccess file...

TIA!!
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

In your httpd.conf, make sure you have

Code: Select all

Allowoverride All
For your specific <directory> only, to keep security up.



Then, in a .htaccess file, put

Code: Select all

AddType application/x-httpd-php .htm
User avatar
RacerX
Forum Newbie
Posts: 21
Joined: Tue Jul 01, 2003 9:21 am
Location: NorthEast USA

Post by RacerX »

Wow, that was quick. Thanks!

A few clarifications please...

Do you need the # before 'AddType'?
Do you need the . before 'htm'?

The only reason I ask, is I looked at my current .htaccess file and the were using that syntax.

Also, since this server is at a hosting provider, do I have access to the httpd.conf file you referred to? I have no experience with those.

Here is the page I am trying to fix: http://www.franchiseprospector.com/devz ... ifieds.htm

Your help is greatly appreciated.
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

You'll need to ask your web host whether or not you can use .htaccess files to alter Apache's configuration for your directory (http://www.franchiseprospector.com/devzone/)
redJag
Forum Newbie
Posts: 18
Joined: Fri Jan 31, 2003 12:17 am

Post by redJag »

>>Do you need the # before 'AddType'?

No, the # is one of the comment out symbols. This would indicate that the line is not being used by Apache.

>>Do you need the . before 'htm'?

Most likely. I haven't actually tested it without the period, I always just put it in. Try it without and find out I guess :)
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

On a performance note, there is a slight performance overhead in implementing this, because you are asking PHP to process .htm files, if there is no PHP in those files (if they are flat) PHP will still be run.

If you do have flat (no PHP) html pages, ensure you use ".html" as the extension to negate the issue.

(My 2p)

:)

Regards,
User avatar
RacerX
Forum Newbie
Posts: 21
Joined: Tue Jul 01, 2003 9:21 am
Location: NorthEast USA

Post by RacerX »

cactus wrote:On a performance note, there is a slight performance overhead in implementing this, because you are asking PHP to process .htm files, if there is no PHP in those files (if they are flat) PHP will still be run.

If you do have flat (no PHP) html pages, ensure you use ".html" as the extension to negate the issue.

(My 2p)

:)

Regards,
Well, even my .htm files would still have SSI processing/includes, so there will be a use for the parsing.

Also, I am trying to set theses pages up so that they do well in search engines and .htm files have a slight advantage over .php (or other extensions).

I will tweak the files today and see what happens.

Thanks again.
User avatar
RacerX
Forum Newbie
Posts: 21
Joined: Tue Jul 01, 2003 9:21 am
Location: NorthEast USA

Post by RacerX »

Here is an even better solution (having no file extensions), but I tried exactly as they had specified, but with no luck. Any suggestions? And yes, I spoke to the server admin and .htaccess config is allowed.

----------------------

Using the .php extension for all your scripts is not necessary, and can be limiting what you can do in the future without breaking links. There are several ways to hide your .php script extension:

(1) Don't hard code file types at all. Don't specify any dots, and most web servers will automatically find your .php, .html, .pdf, .gif or other matching file. This is called canonical URL format:
http://www.xxxxxx.com/page
http://www.xxxxxx.com/directory/
This gives you great flexibility to change your mind in the future.

(2) In an Apache .htaccess file use:
RewriteEngine on
RewriteRule page.html page.php

(3) Force the webserver to interpret ALL .html files as .php:
AddType application/x-httpd-php .php3 .php .html

---------------------
Post Reply