Trying to get php includes to work in an html page

7 replies
  • WEB DESIGN
  • |
I don't want to get rid of the .html file extensions and lose the page rank. I do need to use php includes because sites just seem to keep growing. So far I've tried quite a few ways that haven't worked, and I'll list them here. Some of these were ways that worked for other people in this branch of the wafo.

These were the .htaccess statements I tired one at a time, separated by line breaks. Each blank line is a different try.

Code:
AddType application/x-httpd-php .htm .html

AddHandler application/x-httpd-php5 .html .htm

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

<FilesMatch ".(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>
Each of these would not load the page, but I would get a little download type of pop up saying approximately:

you have chosen to open bike.html
which is a: html file
What should FF do with this file?
The default selection is 'open with firefox.exe'

One bit of code that did work, but in the wrong way was:

Code:
RewriteEngine on
RewriteBase /
RewriteRule ^([^.]+).html$ $1.php [L]
This required changing the file extensions to .php (exactly what I don't want to do) and it left .html in the browser address bar. I also don't want to do that.

Anything else I can try?

baffled (of course that feels like normal to me now)

../lloyd
#html #includes #page #php #work
  • Profile picture of the author aesoft
    Hello... all you should need is the following in the .htaccess (notice no periods before the page extension):
    Code:
    AddType application/x-httpd-php htm html
    {{ DiscussionBoard.errors[2793970].message }}
    • Profile picture of the author Lloyd Buchinski
      Originally Posted by aesoft View Post

      Hello... all you should need is the following in the .htaccess (notice no periods before the page extension):
      Code:
      AddType application/x-httpd-php htm html
      Just tried that one and it brought up the page, but the php include part was just left blank, as if it was on a html page. So basically it didn't work. (sigh)

      Nice to know about the periods though, thank you. Will definitely keep that on file, just in case.

      It might be something that would normally work, but just doesn't with my hosting.
      Signature

      Do something spectacular; be fulfilled. Then you can be your own hero. Prem Rawat

      The KimW WSO

      {{ DiscussionBoard.errors[2794062].message }}
      • Profile picture of the author aesoft
        Originally Posted by Lloyd Buchinski View Post

        Just tried that one and it brought up the page, but the php include part was just left blank, as if it was on a html page. So basically it didn't work. (sigh)

        Nice to know about the periods though, thank you. Will definitely keep that on file, just in case.

        It might be something that would normally work, but just doesn't with my hosting.
        So... the ONLY line in the '.htaccess' file is the one I mentioned?

        Have you attempted to add it through your hosting control panel (i.e. cPanel) "Mime Types" setting instead of trying to do it straight in the '.htaccess'?


        Then, more than likely, there's another setting on the server that's overriding it... or you may have to contact your web host provider (depending on who you use)... or go through all the other changes you've made prior.

        For what it's worth... Sometimes it's not the best idea to edit setting files directly, unless you're comfortable enough to troubleshoot it.
        {{ DiscussionBoard.errors[2794171].message }}
        • Profile picture of the author Lloyd Buchinski
          Originally Posted by aesoft View Post

          So... the ONLY line in the '.htaccess' file is the one I mentioned?
          Yes it is. I'm just trying this out on an unused domain. When I do go public with this I would have a bit more on .htaccess. I suppose I could make this the first line though. Would that be ok? (php dumbie)

          Originally Posted by aesoft View Post

          Have you attempted to add it through your hosting control panel (i.e. cPanel) "Mime Types" setting instead of trying to do it straight in the '.htaccess'?


          Then, more than likely, there's another setting on the server that's overriding it... or you may have to contact your web host provider (depending on who you use)... or go through all the other changes you've made prior.

          For what it's worth... Sometimes it's not the best idea to edit setting files directly, unless you're comfortable enough to troubleshoot it.
          I use DirectAdmin, not cPanel. I've never seen 'mime types' on it, but I'll try poking around. I did put a ticket in to the host with a low priority. I'll bump that up a notch and see what they have to say.

          Thank you for all the comments. More things to think about and understand.

          best wishes
          Signature

          Do something spectacular; be fulfilled. Then you can be your own hero. Prem Rawat

          The KimW WSO

          {{ DiscussionBoard.errors[2794247].message }}
          • Profile picture of the author aesoft
            Originally Posted by Lloyd Buchinski View Post

            Yes it is. I'm just trying this out on an unused domain. When I do go public with this I would have a bit more on .htaccess. I suppose I could make this the first line though. Would that be ok?
            It should be ok.

            The main thing is just to accomplish what you need with the one by itself... and do the same for anything additional you add to it later (you don't have to, but it could save you a LOT of time/aggravation).
            {{ DiscussionBoard.errors[2794288].message }}
      • Profile picture of the author KirkMcD
        Originally Posted by Lloyd Buchinski View Post

        but the php include part was just left blank, as if it was on a html page. So basically it didn't work. (sigh)
        Actually that sounds like it did work. If it didn't work, you would still see the include statement.
        Are you sure the PHP code works?
        {{ DiscussionBoard.errors[2794289].message }}
        • Profile picture of the author Lloyd Buchinski
          Originally Posted by KirkMcD View Post

          Actually that sounds like it did work. If it didn't work, you would still see the include statement.
          Are you sure the PHP code works?
          I do most of my php pages right on the desktop and I never see the include statement show up on the page, just a blank. Not sure why or the details on that.

          They work fine when loaded on the server and I am using the same includes, so I'm quite sure it's ok. If I'm still stuck in a couple of days maybe I'll double check that detail.

          Edit: The php include does work. When I changed one of the pages to .php to check out this

          Code:
          RewriteEngine on
          RewriteBase /
          RewriteRule ^([^.]+).html$ $1.php [L]
          (from the first post) the include worked perfectly.
          Signature

          Do something spectacular; be fulfilled. Then you can be your own hero. Prem Rawat

          The KimW WSO

          {{ DiscussionBoard.errors[2794771].message }}

Trending Topics