Forum Moderators: phranque

Message Too Old, No Replies

.htaccess and 404 redirect problem

Can't get redirection to work under some conditions

         

Soporose

10:20 pm on Feb 9, 2008 (gmt 0)

10+ Year Member



Can somebody explain this to me please...

I'm setting up a 404 redirect on a Linux server and have this line in .htaccess:
ErrorDocument 404 /404handler.php

That works fine EXCEPT when the nonexistent page that's called for has the extension .html -AND- there is subfolder involved.

In other words, the redirect works for all these examples:

http://www.example.com/DoesNotExist.htm
http://www.example.com/DoesNotExist.php
http://www.example.com/DoesNotExist.asp
http://www.example.com/DoesNotExist.html
http://www.example.com/BadFolder
http://www.example.com/BadFolder/DoesNotExist.htm
http://www.example.com/BadFolder/DoesNotExist.php
http://www.example.com/BadFolder/DoesNotExist.asp

But in this case:

http://www.example.com/BadFolder/DoesNotExist.html

There is no redirection and the browser just opens at the home page of http://www.example.com.

My Web development experience is with WinServers and ASP and I'm only just trying to get a grip on Linux and php, so I guess I must be missing something.

Please tell me what it is.

[edited by: encyclo at 1:57 am (utc) on Feb. 10, 2008]
[edit reason] switched to example.com [/edit]

jdMorgan

8:02 pm on Feb 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look for other code that may be diverting control away from your expected directives.

This could be mod_rewrite or mod_alias directives, or it could be that your have Options MultiViews or AcceptPathInfo enabled -- See Apache core for these latter two directives.

Jim

g1smd

8:49 pm on Feb 10, 2008 (gmt 0)

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



A 404 page is displayed when the requested URL does not exist on the site.

I don't like to call it a redirect, because the URL shown in the URL bar does not change. A redirect would also return a 301, 302, or 307 HTTP status code.

In reality, it is a special type of rewrite; one that also forces the HTTP header to return a 404 status code.

Marcia

5:43 am on Feb 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This might be the blind leading the blind <ducking>, but if there are a whole bunch of individual pages to process or redirect (even if it's 404), and they're all in /BadFolder/ couldn't RedirectMatch do the same thing more easily and with less work, by matching all the page name patterns (and cases)and the file extensions that are applicable?

Threads about RedirectMatch [google.com]

jdMorgan

3:43 pm on Feb 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is true, but problems tend to build upon problems, and it's better (IMO) for the long-term sanity of the Webmaster to find out *why* something doesn't work, even when a work-around is available.

If no root cause can be found and no real correction is possible, then of course any available work-around should be applied, so as to allow time to find a new hosting company. -- One that does not subject their customers to anomalous server behaviours. :)

Jim