Forum Moderators: phranque

Message Too Old, No Replies

ErrorDocument relative path for *.mydomain.com and mydomain.com/*

         

anjanesh

10:16 am on May 4, 2009 (gmt 0)

10+ Year Member



For my domain "example.com", I have in my .htaccess
ErrorDocument 404 /error.php

But subdomain.example.com/bad-link.html tries to get subdomain.example.com/error.php which doesn't exist.
How do I specify (relative path) http://example.com/error.php
for *.example.com and example.com/* ?

Thanks

[edited by: jdMorgan at 2:15 pm (utc) on May 4, 2009]
[edit reason] example.com [/edit]

jdMorgan

2:13 pm on May 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either use a symlink, or create an error document in subdomain.example.com's filespace.

I recommend that you avoid the use of scripts to create and serve error documents. Using a script for a critical error document such as 500-Server Error, 403-Forbidden, and 404-Not Found introduces dependencies that can cause errors to cascade.

For example, if a script includes an element shared across all pages on your site (including the error documents), and the element is inadvertently deleted, then the server will generate a 404 response on a normal page, and invoke the 404 error document. But if the 404 error document also requires that deleted element, then attempting to serve that 404 error document will create a second 404 error, and the server will once again invoke the 404 error document... leading to another 404. This will continue until either the server or the client gives up, and your 404 error document will never be served.

The situation for 403 and 500 errors is even worse; I picked the 404 error as an example only because it is simpler to explain and to understand.

Jim

[edited by: jdMorgan at 2:16 pm (utc) on May 4, 2009]

anjanesh

12:15 pm on May 6, 2009 (gmt 0)

10+ Year Member



error.php is a single script with no dependencies - everything inline.

When I added in my subdomain's .htaccess,
ErrorDocument 404 ../error.php

A 404 just shows the text "../error.php"
Either relative path to error.php should work or should be fall back to the default 404

ErrorDocument 404 servers-default-404

jdMorgan

12:36 pm on May 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, the point is that the path to your error document must start with a slash -- as documented. Current-location-relative paths will not work, and cannot work, because the custom error document is served with the URL of the failed resource, and therefore, the meaning of "../" will change, depending on the failed URL.

You could use a canonical URL in your ErrorDocument directive, but then --again, as documented-- all of your 404 errors would result in a 302-Found response, which would be really bad (for search engine rankings).

As stated above, use a symlink in the .htaccess file's directory, if necessary, to point an error document reference in that directory "up one level," or put a copy of the error document into the root directory as seen by/defined for this subdomain.

In general URL-access is restricted to "this domain's root directory," and cannot "go up" higher than that. Allowing HTTP requests to "go as high in the filesystem as they like" would obviously be a security nightmare.

You may want to investigate why you find it necessary to try to access "../" -- Something about your server configuration is, as they say at NASA, "non-optimal."

Jim