Help with .htaccess

Discussion in 'PHP' started by dudehelp, Sep 21, 2006.

  1. #1
    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
     
    dudehelp, Sep 21, 2006 IP
  2. unlisted80

    unlisted80 Peon

    Messages:
    644
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i am not sure what you mean...

    you can include php in html

    <?php include("filename.php"); ?>
     
    unlisted80, Sep 21, 2006 IP
  3. dudehelp

    dudehelp Guest

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    dudehelp, Sep 21, 2006 IP
  4. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #4
    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.
     
    Colbyt, Sep 21, 2006 IP
  5. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #5
    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.
     
    wmtips, Sep 21, 2006 IP
  6. dudehelp

    dudehelp Guest

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Many Thanks.

    I was hoping I was creating the .htaccess correctly.
     
    dudehelp, Sep 21, 2006 IP
  7. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It looks OK to me.........
     
    mad4, Sep 21, 2006 IP
  8. JagoHarry

    JagoHarry Well-Known Member

    Messages:
    2,311
    Likes Received:
    178
    Best Answers:
    0
    Trophy Points:
    183
    #8
    Some hosts have a few oddities with adding AddType support. Always worth chatting to your provider.
     
    JagoHarry, Sep 22, 2006 IP
  9. dudehelp

    dudehelp Guest

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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.
     
    dudehelp, Sep 23, 2006 IP
  10. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #10
    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.
     
    Colbyt, Sep 23, 2006 IP
  11. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
  12. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #12
    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 :D
     
    brian394, Oct 5, 2006 IP
  13. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Failing that, you could 301 redirect the .htm links to the .php pages.
     
    penagate, Oct 5, 2006 IP