Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Redirecting all links to .html files to .php?

    Hello,
    Recently moved site from godaddy to hostgator and their techsupport said that my #include files would not work on .html files and I would need to have only php files.

    Is there a .htaccess fix for this or some way to do it that wont break all of the wordpress links from the blog?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Yes... there's an .htaccess command for this. Or rather a number of .htaccess options. Here's a tutorial:

    http://www.velvetblues.com/web-devel...-files-as-php/

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Hostgator is silly.
    #include is a part of virtual command, so that's an SSI, not PHP (ie: <!--#include virtual="/directory/included.html" -->). Those should be preprocessed as .shtml, not as .php. Now if that is just an include with include '/file'; /* or */ include('file');, then that would be PHP yes.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I completely missed that he was talking about Server Side Includes! Good catch.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts

    We must be getting old to know about the old ssi days!

  • #6
    New Coder
    Join Date
    Feb 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks all. But no this isnt for server side includes just regular ones.. you can see the site here. bestaccident-attorneys.com. The main page and case-evaluations page are php and work fine but everything else wont load any of the includes

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    No, but that doesn't mean that SSI's are not in use. Server side includes are completely independant of the PHP code in use. You can technically (albeit, not at all useful) use PHP to generate output to represent as a .shtml code and pass that back to the server to deal with the SSI's. Typically we don't, as that is slow and kinda pointless; on apache webservers if you *really* wanted to use the SSI directives you can invoke the virtual() function to carry them out. All I was getting at is that #include isn't a PHP directive. If that's in a php file such as:
    PHP Code:
    <?php
    #include 'afile';
    Than it will be ignored as # is a commenting character in PHP (along with //, block with /* */ and doccomment with /** */).


    So the best way is to check your HTML source code. If you literally see in it the #include in an SSI directive, than this would require a removal of the SSI and placement where desired within the php code. The logic is near identical (I'll even specify it as a PHP block for both):
    Code:
    print 'Some PHP code';
    print '<!--#include virtual="/directory/included.html" -->';
    print 'Some more PHP code';
    And assuming the SSI is outputable, you can simply replace it as such:
    Code:
    print 'Some PHP code';
    include "/directory/included.html";
    print 'Some more PHP code';
    If your host states that .html isn't include-able, that's complete rubbish. Think of it as a structural change; you literally take what is read from the call of the include, and place it within your PHP script. The logic would be: include -> close PHP tags -> import content -> open PHP tags, so if your include script is .HTML without any preprocess directives, then its output type would be text so it would insert that into the output buffer at that location. If its in PHP blocks than it would parse that first.

    Unless you mean that you cannot parse .html as .php code (as in you are accessing a .html that should be interpreted as .php), then Fumigator had it correct in the first answer for modifying the handles to accept .html as a php executable type.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,478
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Quote Originally Posted by oftheire View Post
    Thanks all. But no this isnt for server side includes just regular ones.. you can see the site here. bestaccident-attorneys.com. The main page and case-evaluations page are php and work fine but everything else wont load any of the includes
    Server Side Includes are the regular ones for HTML as they work with a .shtml file extension or whatever other extension you map them to. PHP also has includes but they are only just on of hundreds of commands available there - they work with a .php extension or whatever other extensions you configure them to work with.

    If you are using PHP included then all your pages are PHP.

    To have .html externsions treated as PHP you'd just need the following in your .htaccess

    Code:
    AddType application/x-httpd-php5 .html
    AddHandler application/x-httpd-php5 .html
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

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