Forum Moderators: phranque

Message Too Old, No Replies

Apache ignoring .htaccess

.htaccess contents have no effect

         

BobRay

1:16 am on Mar 23, 2006 (gmt 0)

10+ Year Member



I've been trying to get .htm files parsed as .php.

I have it working at my ISP but not locally (at localhost).
I tried all the usual possibilities in .htaccess but none worked.
Finally, I put garbage in the .htaccess file in the root directory
and in the directory I'm working in and it had no effect. The files
still get served up in the browser as usual with no error messages.

It seems that the .htaccess files aren't even being read.

I installed Apache as part of the Xampp package.
I looked in the Apache config file but couldn't see anything
that would make it ignore .htaccess.

Any ideas appreciated.

Bob

lammert

2:28 am on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



BobRay, First of all welcome to WebmasterWorld!

You said that you have .htaccess working at your ISP, so I assume that you have basic knowledge how it works and that the error is not inside the .htaccess file itself. Therefore I think that the problem is in your httpd.conf file. It probably somewhere contains a global AllowOverride None statement which causes Apache to ignore .htaccess files. There are other parameters for the AllowOverride statement which causes it to only accept specific statements in your .htaccess file. The Apache manual will list all possible variations.

BobRay

5:10 am on Mar 23, 2006 (gmt 0)

10+ Year Member



Thanks for the quick reply.
I had already done that.

I finally figured it out based on the fact that a crapped-up
.htaccess file generated no server error.

I'll explain in case it might help someone else.

I was launching the browser from inside Dreamweaver. When I configured the new site,
I failed to specify php/mysql as the server and didn't have the proper directory listed
for the testing server. As a result, Dreamweaver was copying the .htm file to a temp directory and
launching it from there rather than using the actual .htm file so the .htaccess file
wasn't available.

Fixing that still didn't sove the problem because my ISP requires a different AddHandler line
than my version of Apache.

The remote (lunarpages) requires: AddHandler x-httpd-php .html .htm
(nothing else seemed to work there).

but locally, it seems I have to use: AddType application/x-httpd-php .htm .html

My workaround is to put the second one in the directory above my working directory and
rename the .htaccess file in the local dir until I need to upload it to the remote. If I leave
the local .htaccess file there, it doesn't work. There may be some kind of conflict between the two.

It would be great if someone could suggest an alternative that might work on both or a command
for the local .htaccess that wouldn't conflict with the one in the dir above it. I'm
fairly new to Apache and don't really understand the AddHandler, AddType, and Server Parsed
commands so I'm kind of throwing darts blindfolded.

Thanks again,

Bob

jdMorgan

5:15 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AddHandler tells Apache how to handle each file by filetype. So "AddHandler server-parsed .html" tells Apache that it should activate the PHP module to parse any requested .html file for PHP code included in that file.

AddType tells Apache what MIME-type header it should send in the response header sent to the client (browser) with each filetype. This should not affect whether the file is parsed for PHP code, but only affect the MIME-type header sent back to a browser.

The browser's behaviour changes because of this MIME-type header. For example, if it's text/html, display it in the browser, and if it's video/wmv, either activate the Windows Media Player plugin (if available and enabled), or open an external Media Player to 'play' it. Internet Explorer further complicates this by trying to identify the MIME-type automatically, based on the first few bytes of the file. If it (thinks it) can do so, it will ignore the MIME-type header sent by the server.

I can't answer your main question, but hopefully, that background may help.

Jim

BobRay

9:42 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



Thanks,it helps a lot.

If I want to have both .htm and .html files handled
as php, is it better to have two lines:

AddHandler server-parsed .html
AddHandler server-parsed .htm

or a single line:

AddHandler server-parsed .htm .html

Also, how does Apache know from this line that I want php processing without php being specified in the .htaccess file?

I think part of my problem is the my ISP is using
SuPHP which seems to require different syntax in the .htaccess files.

Bob

jdMorgan

10:26 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No difference as far as AddHandler goes... Put as many filetypes in there as you like.

Apache doesn't know what script handlers you want to run. But it runs the PHP parser because PHP is installed and configured to run (we presume).

Jim

BobRay

6:51 am on Mar 26, 2006 (gmt 0)

10+ Year Member



Thanks.

Here's a little more information for those with similar problems.

I found that at my hosting service I could do without
.htaccess for this by going to "Apache Handlers"
in CPanel.

I entered:

Extension: .htm .html
Handler: x-httpd-php

The add-handler page in CPanel listed the available handlers so presumably if the host is not running SuPHP, some other handler syntax would show up.

The cost of this is that ALL .html and .htm files in all directories are run through the .php handler but I don't notice any speed degradation.

Even if you want to use .htaccess for this, going to the Apache add-handler page in CPanel might show you the correct syntax for your AddHandler directive.

Bob