Results 1 to 5 of 5

Thread: .html parsed as .php

  1. #1
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default .html parsed as .php

    Quote Originally Posted by ko_tish View Post
    If you can't or don't want to rename your existing files, you could force your webserver to parse even .html-files for PHP code. If you use Apache, you could add the "AddType application/x-httpd-php .php .html" to your .htaccess. But this is another story.
    I found this in another thread and may want to use it for something not directly related to that thread. What I want to know is the best way to actually do this and, if this would result in any significant load on the server for .html pages that contain no PHP code. Also, could there be any other drawbacks to doing this?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    What I want to know is the best way to actually do this
    The best (well, only) way to do it is as mentioned, with an .htaccess or in the main httpd.conf file.
    and, if this would result in any significant load on the server for .html pages that contain no PHP code.
    Depends. The main cost would be that of sending it through a PHP interpreter, which is less of a problem with mod_php, but more of a problem if you're using CGI, which will start up a new PHP interpreter process with each page processed.
    Also, could there be any other drawbacks to doing this?
    Well, the standard PHP opening tags (<?, <?php, <script language="php">) would be out of bounds. Can't see that being much of a problem with HTML pages, but the former interferes with the XML prologue on XML or XHTML pages.

    You're better off using mod_rewrite to redirect certain .html URLs to corresponding PHP pages, really.
    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!

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I find myself with this answer, in the situation I imagine many of the folks we help who are newbies do. After all, I am practically a newbie with .htaccess and PHP. That is - I barely understand the answer. So, more questions:

    and, if this would result in any significant load on the server for .html pages that contain no PHP code.
    Depends. The main cost would be that of sending it through a PHP interpreter, which is less of a problem with mod_php, but more of a problem if you're using CGI, which will start up a new PHP interpreter process with each page processed.
    How can I tell which is being used by the server? I'm just the webmaster, not the server admin.

    You're better off using mod_rewrite to redirect certain .html URLs to corresponding PHP pages, really.
    Where does that go? Can you give me an example for - say:

    somedomain.com/index.html

    being redirected to:

    anotherdomain.com/somedir/somedir/index.html

    Also, is there a way (example please, if yes) of redirecting all requests to one domain to a directory on another domain, even if the pages only exist on the other domain that is being redirected to?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    How can I tell which is being used by the server? I'm just the webmaster, not the server admin.
    Generally if you log in to your server you can see (if not modify) the config for your virtual host in /etc/httpd.conf (or /etc/apache2/httpd.conf, or similar).
    Where does that go? Can you give me an example for - say:

    somedomain.com/index.html

    being redirected to:

    anotherdomain.com/somedir/somedir/index.html
    I think the .htaccess file in / would look something like:
    Code:
    RewriteEngine On
    RewriteRule ^/index.html$ http://anotherdomain.com/somedir/somedir/index.html
    Also, is there a way (example please, if yes) of redirecting all requests to one domain to a directory on another domain, even if the pages only exist on the other domain that is being redirected to?
    Certainly:
    Code:
    RewriteRule ^/(.*) http://anotherdomain.com/somedir/somedir/$1
    They're just standard regular expressions, although the syntax differs slightly (which always confuses me) due to there being so many reserved characters for regex commonly found in URLs.
    Last edited by Twey; 04-14-2007 at 03:03 PM.
    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!

  5. #5
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    And besides htaccess is to powerful to just leave aside soooo -
    http://www.javascriptkit.com/howto/htaccess.shtml

    Its got alot of detaisl and even gives all the error codes too, all the navigtion for htaccess is at the bottom...

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
  •