I need some help here... I want to use some PHP code within .htm pages. I cannot change them all to .php due to links. I understand this can be accomplished using .htaccess file. The problem is I am not fully understanding how to create this file and where to place it. Here is what I have done: 1. opened notepad and put ONLY the following line in it: AddType application/x-httpd-php .php .htm .html 2. I saved the file as .htaccess (it looks exactly like that, no .txt or anything else) 3. I loaded it to my server in the same directory as my index page (actually all my pages). I am not very good at organizing the directory so everything is in the same place. When I do this. I get a internal server error 500. When I take it out, my site functions properly...just as HTML. Does anyone know what i am doing wrong? Could there already be an .htaccess file somewhere that I cannot find? My hosting account supports PHP and tell me its ok to use an .htacces file. Any suggestions would be greatly appreciated. Thanks
sorry if I am not too clear. I just need to use php in .htm pages. All my pages are .htm and i have a snippet of php code to put in each page (geo targeting stuff). As I mentioned, I cannot change the .htm extension. My php code is fine, I just do not understand how to create a .htaccess file and where to place it on the server. I created an .htaccess as descibed above, but sure if it is correct. If I posted in the wrong forum...my apologies.
I can't tell you how to write because I let cPanel do it for me. You just need to set the apache handler to parse the htm pages. Something like <sometag here> htm server-parsed The < > are not used. Used here for clarity.
No, server-parsed is for SSI, but question was how to interpret the .htm by php. dudehelp, you are doing almost right, instruction you posted works in many cases. But it really depends on Apache configuration, hoster, etc. And I doubt you need to place a .php there. So you can try: 1. AddType application/x-httpd-php .htm .html 2. AddType application/x-httpd-php4 .html .htm 3. If it doesn't work, I would recommend to ask your hosting provider for advice.
Thanks for all of your assistance. I am still having problems. My hosting company says the file looks fine, but for some reason it is not working. They are unable to provide direction on this. I am looking for some further assistance here, because I am sure it is something real simple. here is all I have in the .htaccess RemoveHandler .html .htm AddType application/x-httpd-php .php .htm .html I have created several test pages in .htm, and none of them show the PHP funtion in the browser (I am trying to geo target ads). If i create a test page and name it .php it works fine. My site is hosted on a linux box, does this make a difference in the .htaccess? is there something different I need to do. Please help.
I was not able to get a test file to work on my server either. wmtips may be right when he says that server-parsed only adds the include file function of php to an htm or html page. The include file function does work well.
These may help... Parsing PHP with HTML file extension PHP, HTML & .htaccess Need help with .htaccess file Apache Tutorial: .htaccess files AddType Directive
Also wanted to mention, I once had a hosting provider where this didn't work... AddType application/x-httpd-php .php .htm .html Code (markup): but this did work... AddType x-httpd-php .php .htm .html Code (markup): maybe worth a shot