Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: enabling php in html files with .htaccess

  1. #1
    Join Date
    Jun 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default enabling php in html files with .htaccess

    I've been using some very simple php includes to simplify management of some sites I have built. With one site I had already uploaded a large number of .html files so rather than renaming them I added the line "AddType application/x-httpd-php .php .htm .html" to the end of the .htaccess file on the web server. With sites I have built since then I just give all the files a .php extension.

    After getting tired of uploading files to my sites to test them, I decided to enable it on my machine so I could test locally. I am an Oracle DBA by day so I already had apache (oracles version) running on my machine, so I installed the latest php and enabled it in apache.

    I copied the entire contents & directory structure of two sites to the htdocs folder in the apache directory so that they each have a directory under the htdocs file.

    Now, my pages I have built in the newer site with a .php extension render fine, with my menu's that are stored in separate.php files showing up as expected. But with the older site that I added the AddType application/x-httpd-php .php .htm .html line to the .htaccess file the php includes are not showing up, despite me adding the neccesary line to the .htaccess file(s) I added the line first to the .htaccess file in the directory where the pages reside, and when that didnt help added the line to the .htaccess file in the root (htdocs) directory.

    What am I missing here?

    thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Here's some basic info on this--
    http://www.dynamicdrive.com/forums/s...ad.php?t=17398

    Beyond that, not sure what's wrong. Might be something else about your configuration.

    Perhaps locally you are still viewing the .htm as a file and .php as, by default, through the webserver? I dunno. Seems too simple, though.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Here's some basic info on this--
    http://www.dynamicdrive.com/forums/s...ad.php?t=17398

    Beyond that, not sure what's wrong. Might be something else about your configuration.

    Perhaps locally you are still viewing the .htm as a file and .php as, by default, through the webserver? I dunno. Seems too simple, though.
    Nope, accessing both files through the webserver, ie. http://localhost:7777/<mywebdir>/

    Even renaming the pages with a .php extension doesnt do it, I know I'm missing something simple here, just dont know what..

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm.... not sure, then.
    Does copying the text from each into a new .php file work?
    Maybe there's some lasting ghost trace of their .htm past, so your computer won't read them correctly.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Hmm.... not sure, then.
    Does copying the text from each into a new .php file work?
    Maybe there's some lasting ghost trace of their .htm past, so your computer won't read them correctly.
    Correction - changing the file to a .php extension did work - but I still dont know why the php is not working when they have the .html extension.

    I stripped out everything from the .htaccess file so all it has is:

    AddType application/x-httpd-php .php .htm .html
    AddHandler application/x-httpd-php .html .php .htm

  6. #6
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Not sure about local servers, but on my web servers I had to place it OUTside the root dir. One server it didn't work unless it was inside the root, the other it had to be outside.

    Worth a shot I guess..

    OHH.. one other thought... you said you downloaded the latest version of php... would that be php5? If so your ,htaccess needs to have php5 added to the lines.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This is a bad idea anyway -- parsing all pages as PHP is a waste of resources.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Depends on your setup.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, parsing a pure HTML page as PHP is always a waste of resources. It may be a waste of resources that the server in question can afford, but it's still a waste of resources.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Nope.

    If you want a site that has .htm files parsed as php, and all of your pages are .htm, and all have php scripting... no waste.
    Same would apply to other formats, like .js, .jpg, etc.

    Now... each .htm that DOESN'T have php scripting IS a waste, but the amount of waste varies by your setup and how much does have php, etc.

    There isn't really a way around it to determine which should be parse and which should not, though. So if you want that, just live with it, I guess.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •