Welcome to WebmasterWorld Guest from 54.163.52.98

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

question regarding PHP code in .htm files instead of .php extension

is this advisable?

     

ebess

6:35 am on Aug 8, 2001 (gmt 0)

10+ Year Member



I am just starting to learn PHP and many of the tutorials that I have come across provide sample code to be embedded into your .htm file. To me, this implies that the server should be able to recognize that the parsed PHP code, delineated by it's <? and ?>, and process that along with the html.

When I try this on my server, however, it doesn't work (although it works fine if I rename the file to something.php instead of something.htm)

I would rather use .htm extension though, as I think it's better for search engines and I don't care to notify folks that I'm doing anything dynamic in the background by having the php extension.

I was able to get this to work by modifying my .htaccess file to add a line as follows:

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

So I guess my real questions are:

1) Is it normally necessary to add this line to your .htaccess file in order to process PHP in .htm files?

2) Is there any reason NOT to add this line to my .htaccess file? In other words, is there any reason (performance, security, whatever..) why I wouldn't want my server to process .htm files with PHP code in them?

As I mentioned, I'm just getting started with this so forgive me if the question seems a bit inane..

Thanks for any help that can be provided :)

-ebess-

sugarkane

12:16 pm on Aug 8, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Is it normally necessary to add this line to your .htaccess file

Yes :)

You need to tell the server which files to run through the PHP engine, and that is the way you do it.

> Is there any reason NOT to add this line to my .htaccess file

You'll take a performance hit on non-PHP .htm pages as they'll still be parsed for PHP coding. If most of your pages are straight HTML then you'd probably be better off putting your PHP pages in a seperate directory and only putting the .htaccess file in there.

ebess

6:26 pm on Aug 8, 2001 (gmt 0)

10+ Year Member



thanks, sugarkane, for your help! that was exactly what I needed to know :)

-ebess-

WebGuerrilla

6:44 pm on Aug 8, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




If you need to use PHP throughout various locations in your site and putting them all in the same directory isn't advisable, you can add just one html extension to your .htaccess

If all your current pages are .htm then you could just add

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

And then just rename the pages containing the PHP to .html That way, the non-php pages won't get parsed.

ebess

7:07 pm on Aug 8, 2001 (gmt 0)

10+ Year Member



even better!

that's brilliant

thanks!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month