+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: force .html files to be executed as .php

  1. #1
    axs07634 is offline x10Hosting Member axs07634 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    4

    force .html files to be executed as .php

    Hi, I am on the boru server. I am trying to force my html files to be parsed as php, but no luck so far. I have tried adding all of the following to my .htaccess file in all possible combinations and permutations:

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

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

    AddType x-httpd-php .html
    AddHandler x-httpd-php .html

    and so on..

    I have tried setting .htaccess to 755 and to 777. I have tried setting the html file to 755 and 777. I've tried everything. I KNOW I can add a php extension instead of an html extension and it'll work, but for specific reasons I need to keep the .html extensions.

    Anyone know what should be done?

  2. #2
    MaestroFX1's Avatar
    MaestroFX1 is offline Community Advocate MaestroFX1 has a spectacular aura about
    Join Date
    Feb 2008
    Location
    Area 51
    Posts
    1,577

    Re: force .html files to be executed as .php

    Create .htaccess with
    ---------
    AddType application/x-httpd-php5 .html .htm
    ---------

    Set file permission to 0644

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: force .html files to be executed as .php

    Note that doing this means all HTML files will be passed through the PHP interpreter, even those with no PHP, which will increase your resource usage.

    If your "specific reason" for not using an extension of ".php" is that you're concerned about the appearance of URLs (always state your overall goal when asking for help), you should use rewriting or implement clean URLs (a search of these forums or a web search at large will turn up instructions as to how) so the extension doesn't appear publically.

    Since pages using PHP aren't executed directly, they shouldn't have the execute bit set. Read up on the meaning of permissions and file execution under Linux.
    Last edited by misson; 04-20-2011 at 10:11 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    axs07634 is offline x10Hosting Member axs07634 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    4

    Re: force .html files to be executed as .php

    Thank you both for your replies,

    I implemented MaestroFX1's advice and it worked this time. Beats me why it didn't work before. The only thing I had done differently was setting inappropriate permissions on .htaccess.


    misson thank you for your reply. I agree - I see now that I don't need to force this behavior on all html files, just one in particular. Could you point out how to make sure that index.html is parsed through PHP5?

    If this can't be done the alternative would be to force calls to index.html to go to index.php, but I don't want to do this with a simple redirect for SEO and link maintenance purposes. I don't know if that is even possible. Is it?

    Thanks for your help.

    Regards,
    axs

  5. #5
    MaestroFX1's Avatar
    MaestroFX1 is offline Community Advocate MaestroFX1 has a spectacular aura about
    Join Date
    Feb 2008
    Location
    Area 51
    Posts
    1,577

    Re: force .html files to be executed as .php

    Remove the previously suggested text by me and now add:

    -----------
    <FilesMatch "some_particular_file.htm">
    SetHandler application/x-httpd-php5
    </FilesMatch>
    -----------

    Remember index.htm takes preference over index.php unless mentioned otherwise.

    Still,can't understand the love for whatever you are trying to do!

  6. #6
    denzil is offline x10 Sophmore denzil is an unknown quantity at this point
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    134

    Re: force .html files to be executed as .php

    why don't you just leave out index.html and put in index.php?

  7. #7
    stardom's Avatar
    stardom is offline x10 Sophmore stardom is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    Lexington, Kentucky
    Posts
    162

    Re: force .html files to be executed as .php

    Quote Originally Posted by denzilb22 View Post
    why don't you just leave out index.html and put in index.php?
    Exactly. A single page can be ran in php without having to designate it to. just have your nav bar set up like this. index.php - about.html - contact.html....etc...

    Just use the server do it on its own.

  8. #8
    axs07634 is offline x10Hosting Member axs07634 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    4

    Re: force .html files to be executed as .php

    Quote Originally Posted by MaestroFX1 View Post
    Remove the previously suggested text by me and now add:

    -----------
    <FilesMatch "some_particular_file.htm">
    SetHandler application/x-httpd-php5
    </FilesMatch>
    -----------

    Remember index.htm takes preference over index.php unless mentioned otherwise.

    Still,can't understand the love for whatever you are trying to do!
    Thanks again for your input, MaestroFX1!


    ...ok, for everyone who asked...I sheepishly explain: I have a whole site that has been built with many many pages all linking to the homepage (index.html). Now, all of a sudden I need to have the home page perform some nifty PHP stuff...so here I am thinking:

    1. do I create index.php and use mod_rewrite and pass index.php to every index.html request?
    2. do I do a 301 redirect to index.php for every index.html request?
    3. or do I just add PHP to index.html and have it parsed as PHP?

    It's either one of these or go and rewrite every page.
    For me option 3 seemed like the best idea. Anyone object?

    I will try Maestro's suggestion and see how it works.
    Last edited by axs07634; 04-21-2011 at 11:18 PM.

  9. #9
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: force .html files to be executed as .php

    A rewrite would be best, as a quick solution. The Right Way of going about it is to leave off the default index file ("index.html", "index.php") from URLs since it's completely unnecessary, and use clean URLs and leave off the extension for other pages (e.g. "/foo/bar", rather than "/foo/bar.php").
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  10. #10
    axs07634 is offline x10Hosting Member axs07634 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    4

    Re: force .html files to be executed as .php

    Quote Originally Posted by misson View Post
    A rewrite would be best, as a quick solution. The Right Way of going about it is to leave off the default index file ("index.html", "index.php") from URLs since it's completely unnecessary, and use clean URLs and leave off the extension for other pages (e.g. "/foo/bar", rather than "/foo/bar.php").
    I will definitely be going through all the files and SLOWLY rewriting them to point back to the domain and not the index file (I suspect that the person who designed the site was too lazy to setup a test server and instead had everything in a folder, so he referenced index.html instead of the the root), but I need a temporary fix.

    As for using a rewrite - I didn't want to do this b/c I thought that it would create a duplicate content violation for search engines. That is if I have Page X linking to mydomain.com/index.html and another page linking to mydomain.com, both would return the same content. Wouldn't that be considered duplicate content?

    Regards,
    axs

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. FTP for HTML, etc. Files
    By epotzck in forum Free Hosting
    Replies: 2
    Last Post: 04-19-2010, 12:15 AM
  2. Where to put the HTML files
    By lmack95 in forum Free Hosting
    Replies: 0
    Last Post: 02-09-2010, 04:17 AM
  3. Can't uplaod HTML files?
    By poepoe1122 in forum Free Hosting
    Replies: 9
    Last Post: 08-20-2009, 12:39 PM
  4. Root PHP files not getting executed
    By cool_dude_99 in forum Free Hosting
    Replies: 3
    Last Post: 05-09-2008, 09:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers