14 replies
What I want is for my .html files to be parsed as if they are .php

I have tried adding to the .htaccess :

AddHandler x-httpd-php .html .htm

and

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

and

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

The last one actually causes the browser to want me to open it with an application so I know that the .htaccess is being read.

I have also tried adding via the cpanel apache handler.

But it is not parsing it as .php.

So, for example if I use the code:

<?='hello'?>

It is showing as that in the source code.

Any help?

Thanks,

Ben Shaffer
#html #parsing #php
  • Profile picture of the author Voon
    I use this in .htaccess

    Code:
    <FilesMatch ".(htm|html)$">
      SetHandler application/x-httpd-php
      ForceType application/x-httpd-php
    </FilesMatch>
    Originally Posted by BenShaffer View Post

    <?='hello'?>
    This would require 'short_open_tag' enabled in PHP.
    Signature

    .

    {{ DiscussionBoard.errors[1577497].message }}
  • Profile picture of the author BenShaffer
    Thanks. Weirdly, this is causing the browser to ask how to open the file.

    Any other suggestions?

    Ben Shaffer
    {{ DiscussionBoard.errors[1577513].message }}
    • Profile picture of the author Tim Brownlaw
      Ben - what hosting are you using?

      I've given the same solutions as above in one of my installation guides for my dynamic link cloaking - as an aside and I've not actually tried it... naughty me!

      So naturally I'm concerned as it appears it don't work on some hosting servers!

      I scoured Google on this and there are others ( strangely enough ) experiencing the same problem you are seeing.

      Some - and I'm only regurgitating what some folk reckon works - suggest the following.

      Code:
      AddType application/x-httpd-php .php .htm .html
      AddHandler x-httpd-php .php .htm .html
      Disclaimer : This is untested (by me) and looks strange so it's only something to try...

      I'd contact your hosting techs and see what light they can shed on this..

      Let us know what you find! I'd certainly be interested.

      Cheers
      Tim
      Signature

      Great Success is built from many little successes!

      http://www.timbrownlaw.com - My Wee Part of the World.

      http://www.LookingOverMyShoulder.com

      {{ DiscussionBoard.errors[1577700].message }}
  • Profile picture of the author BenShaffer
    Hi Tim,

    I just bought a site so am currently on their dedicated server with my own cpanel. Not really sure a lot more than that apart from the following pasted from cpanel:

    Hosting packagestandardServer NamehostcPanel Version11.24.5-STABLEcPanel Build38506Themex3Apache version1.3.41 (Unix)PHP version5.2.6MySQL version5.0.85-community-
    log Architecturei686Operating systemLinux
    I tried what you said and it had the same problem - asking which app to open it with.

    All I really want to do at this point is to use includes from the header and footer. Perhaps there is another way to do this without changing the file extension?

    Ben Shaffer
    {{ DiscussionBoard.errors[1577872].message }}
    • Profile picture of the author Tim Brownlaw
      Originally Posted by BenShaffer View Post

      All I really want to do at this point is to use includes from the header and footer. Perhaps there is another way to do this without changing the file extension?
      Ben, I found this very quickly and it should help you out with what you want to do.

      I've had a very quick "Squiz" over this and it looks like the answer is in there..

      WWW FAQs: How do I include one HTML file in another?

      It would still be good if we can get your PHP issues sorted.

      Cheers
      Tim
      Signature

      Great Success is built from many little successes!

      http://www.timbrownlaw.com - My Wee Part of the World.

      http://www.LookingOverMyShoulder.com

      {{ DiscussionBoard.errors[1580014].message }}
  • Profile picture of the author KirkMcD
    Originally Posted by BenShaffer View Post

    AddType application/x-httpd-php .php .htm .html
    AddHandler x-httpd-php .php .htm .html
    It should be

    Code:
    AddType application/x-httpd-php .htm .html
    AddHandler x-httpd-php .htm .html
    Take out the ".php"
    I don't think you need the AddHandler though. Try it without it.
    {{ DiscussionBoard.errors[1578256].message }}
  • Profile picture of the author BenShaffer
    Kirk,

    Forgive me if I am mistaken, but are you not just repeating what I said in my original thread?

    B
    {{ DiscussionBoard.errors[1578374].message }}
  • Profile picture of the author Ross Dalangin
    For web servers using PHP as apache module:

    Code:
    AddType application/x-httpd-php .html .htm
    For web servers running PHP as CGI:

    Code:
    AddHandler application/x-httpd-php .html .htm
    So use only one of them.

    You can also try

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.*).htm$ $1.php [NC]
    Or
    Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.+).htm$ http://yourdomain.com/$1.php [R,NC]
    or
    Code:
    RewriteRule ^(.+).htm$ http://yourdomain.com/$1.php [R=302,NC]
    or else make it worst
    Code:
    RewriteRule terms.html terms.php
    {{ DiscussionBoard.errors[1578774].message }}
  • Profile picture of the author Ken Shorey
    If your host is running php version 5, you should try:
    AddType application/x-httpd-php5 .html .htm
    {{ DiscussionBoard.errors[1579662].message }}
  • Profile picture of the author mlangille
    Hey Ben

    Here's a software tool PhpActivator that will help you out.
    "O Yeah" it's free PhpActivator


    Michael
    {{ DiscussionBoard.errors[1580456].message }}
  • Profile picture of the author phptechie
    Check your PHP version & use appropriate handlers with it version like php3 or php5
    {{ DiscussionBoard.errors[1582499].message }}
  • Profile picture of the author lisag
    Originally Posted by BenShaffer View Post

    What I want is for my .html files to be parsed as if they are .php

    I have tried adding to the .htaccess :

    AddHandler x-httpd-php .html .htm

    and

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

    and

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

    The last one actually causes the browser to want me to open it with an application so I know that the .htaccess is being read.

    I have also tried adding via the cpanel apache handler.

    But it is not parsing it as .php.

    So, for example if I use the code:

    <?='hello'?>

    It is showing as that in the source code.

    Any help?

    Thanks,

    Ben Shaffer
    Voon mentioned this earlier, but I don't see where you picked up on it.

    where you have
    Code:
    <?='hello'>
    try
    Code:
    <?PHP='Hello';?>
    That should do it for you as long as your .htaccess file is configured properly. Here's what I use:

    Code:
    AddHandler x-httpd-php .html .htm 
    AddHandler php-script .php .html .htm 
    
    AddHandler php5-script .php .html .htm 
    
    AddType application/x-httpd-php .htm 
    AddType application/x-httpd-php .html
    Signature

    -- Lisa G

    {{ DiscussionBoard.errors[1582779].message }}
    • Profile picture of the author Tim Brownlaw
      Originally Posted by lisag View Post

      Code:
      <?PHP='Hello';?>
      That's in between the short and long form.

      It should be
      Code:
      <?php echo 'Hello';?>
      I always use the long form. That way it will always work between servers. It's not written in stone but I consider it part of my "Good coding practice".
      Signature

      Great Success is built from many little successes!

      http://www.timbrownlaw.com - My Wee Part of the World.

      http://www.LookingOverMyShoulder.com

      {{ DiscussionBoard.errors[1585303].message }}
      • Profile picture of the author lisag
        Originally Posted by Tim Brownlaw View Post

        That's in between the short and long form.

        It should be
        Code:
        <?php echo 'Hello';?>
        I always use the long form. That way it will always work between servers. It's not written in stone but I consider it part of my "Good coding practice".
        Right you are and I know better. Sometimes I don't slow down and re-read when I post. Good catch!

        Thanks,

        Lisa
        Signature

        -- Lisa G

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

Trending Topics