View Full Version : PHP Includes | .htaccess

09-04-2003, 10:37 AM

I have PHP includes within .html files on my website. They seem to have gone missing however.

I had fixed this problem originally by uploading a .htaccess file. But when I do that now, I go to the site and it's inaccessible...asking if I want to download the site.

What should I do?

09-04-2003, 07:18 PM
The site is inaccessible indicates you have a syntax error in your htaccess file. Delete it from the website and see if you can get to view your home page.

Re: the includes. You lost me. You're trying to do PHP includes include() within an html file? Were you processing each html file as if it were a PHP file by telling apache to do so within htaccess? Why?

09-09-2003, 05:46 PM
All of my files have a .html extension. The .htaccess should (and did) parse the php within my .html pages. Why all of a sudden did it stop...?

I'm using the same .htaccess as before the new WestHost.

09-10-2003, 08:33 AM
Well it could be because the new server hasn't been set up to parse html files through the PHP engine. Do you have a line in your htaccess file like this:

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

09-10-2003, 02:33 PM
Yeah, my .htaccess that worked before:

AddType text/css .css
AddType application/x-httpd-php .php4 .php .htm .php3 .inc .html

--:> Seems somebody else would have had this problem. WestHost won't return my emails so I'm not really sure what's up.

09-10-2003, 07:58 PM
Hmm.. not sure what to tell you then.

If all of your files are php files that look like html files you could try to use a mod_rewrite instead such that any calls for .html will substitute the .php and then process them.

09-10-2003, 09:50 PM
I'm stumped :?

When I try it, I get the same thing: it tries to download the file (and it's being sent as plain text!). I'm sure it must be a configuration option for Apache or something that is preventing you from doing that. Interesting to note, however, if you add that type for a unique file extension, e.g. .moo it will work and PHP interprets it! At first I thought it might be the AllowOverride option in Apache config - I checked though and that is set to All by default, so it can't be that.

If I do figure it out I will let you know. Meanwhile you might want to send WestHost a support request concerning this. Let us know how it goes.

09-10-2003, 10:00 PM
yeah, i've always parsed .html as php by directive in .htaccess as you are. As soon as they moved me over to 2 the browser did not know how to handle the application type I was adding. Here's the problem (the techs at WH fixed on my one site, and I did the others):

You need to keep your .htaccess as is. Now that php is an apache module and not a cgi app, there is a little conflict with ssi handlers and php handlers in your httpd.conf file. I edited my own, but you can let WH support know that your'e using .htaccess to parse html as php, and now it's a problem due to ssi handlers and php4.c handlers in httpd.conf. They should know just what you mean.

Here's what my changed code looks like in ssi section (note that the line commented out with the # includes ".html". I don't want to parse .html with text/html...I want to parse it with php:

# To use server-parsed HTML files
** * #
** * AddType text/html .shtml
** * #AddHandler server-parsed .shtml .html .htm
** * AddHandler server-parsed .shtml .sht

Here's what it looks like in php4.c section (you don't need to have ".html" here as you are directing it to parse .html as php in your .htaccess):

<IfModule mod_php4.c>
** * * * AddType application/x-httpd-php .php .php4 .php3 .phtml
** * * * AddType application/x-httpd-php-source .phps
** * </IfModule>

Yeah, my .htaccess that worked before:

AddType text/css .css
AddType application/x-httpd-php .php4 .php .htm .php3 .inc .html

--:> Seems somebody else would have had this problem. WestHost won't return my emails so I'm not really sure what's up.

09-10-2003, 10:14 PM
Thanks Bailey. That works perfectly. You just forgot to point out that the VDS/Apache needs to be restarted for the changes to take effect - at least it did for me. I typed "restart" at the SSH command prompt, but restarting the VDS from the Site Manager should also do the trick.

09-10-2003, 10:43 PM
oh yeah, I forgot about the restart. glad to help. It's nice when we can share our fixes during the upgrade and help each other out.

09-11-2003, 04:28 AM
Yup... This forum kicks ass.

09-11-2003, 06:04 AM
Actually, my includes were in a sub-directory. When I put the .htaccess file in that directory it worked as normal. Previously, I had my .htaccess file in the 'WWW' directory- this worked...so that is why I was confused. I thought that .htaccess affected sub-directories.

Thanks for your help!

09-11-2003, 08:29 AM
If that were the case - then password protection would be a real b*tch. :D

Glad you got it working.

09-11-2003, 02:26 PM
.htaccess does affect sub-directories (or at least it is supposed to)...

09-11-2003, 05:53 PM
Yes, affect not effect-

You get to learn a little about English here too!

09-12-2003, 05:57 AM
>> .htaccess does affect sub-directories

Whoops. you're correct. :oops: I should have thought about that one more before posting.

In thinking about this more isn't that a setting the server admin can set in the httpd.conf file? Since rights cascade - can a security setting in an htaccess file override one from a higher level?