force .html files to be executed as .php

axs07634

New Member
Messages
4
Reaction score
0
Points
0
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?
 

MaestroFX1

Community Advocate
Community Support
Messages
1,577
Reaction score
60
Points
0
Create .htaccess with
---------
AddType application/x-httpd-php5 .html .htm
---------

Set file permission to 0644
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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:

axs07634

New Member
Messages
4
Reaction score
0
Points
0
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
 

MaestroFX1

Community Advocate
Community Support
Messages
1,577
Reaction score
60
Points
0
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!
 

denzil

New Member
Messages
134
Reaction score
3
Points
0
why don't you just leave out index.html and put in index.php?
 

stardom

New Member
Messages
158
Reaction score
2
Points
0
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.
 

axs07634

New Member
Messages
4
Reaction score
0
Points
0
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:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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").
 

axs07634

New Member
Messages
4
Reaction score
0
Points
0
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
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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?
Possibly; I'd need to look into it. I suspect (given how pervasive "index.*" is as a default directory index) that search spiders would consider the two URLs to be equivalent. If you're really worried, you can have your rewrite rule send an external redirect, forcing the index file name to be included in the URL. Once all pages have been converted, remove the external redirect.
 
Top