Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get the apache server to issue a custom 404 error for invalid subdomains. The following is the relevant part of the httpd configuration:

Alias /err/ "/var/www/error/"
ErrorDocument 404 /err/HTTP_NOT_FOUND.html.var

<VirtualHost *:80> # the default virtual host
  ServerName site_not_found
  Redirect 404 /

<VirtualHost *:80>
  ServerAlias ??

What I get instead is this:

Not Found

The requested URL / was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I don't understand why a URL to produces a 404 error without custom error as shown above while a URL to produces the full custom 404 error.

Can someone advise on this. Thanks.

share|improve this question
What's the Redirect 404 / supposed to be doing? – Shane Madden Sep 14 '12 at 5:59
@ShaneMadden, I want the page to show a 404 error. Is there something wrong? Please help. Thanks. – Question Overflow Sep 14 '12 at 7:10
Right, but can you clarify what that configuration was put there to do? It's invalid. Anyway, can you provide the output from Apache's error log after a request is made that returns the "bad" error page? – Shane Madden Sep 14 '12 at 7:13
@ShaneMadden, I suppose Redirect 404 / would redirect any URL that does not match any vhost listed below to a 404 error page. I have been looking at the error log every time I restart httpd server, but so far no errors produced except for the usual shutdown and startup notices. – Question Overflow Sep 14 '12 at 7:26
@ShaneMadden, can you explain why it is invalid? Because it does produce the "Not Found" error upon entering of a non-existent subdomain. – Question Overflow Sep 14 '12 at 7:33
up vote 1 down vote accepted

Interesting; that syntax is only documented to work with a 410 status code.

In any case, the use of the Redirect 404 / explains the inability to serve the custom error page - it's affected by the Redirect, too.

Giving the 404'ing vhost its own empty DocumentRoot is one option, since it can then "normally" 404 the requests without applying it globally to everything in the vhost (including the error page).

Alternatively.. if Redirect works for 404, perhaps RedirectMatch can, too?

RedirectMatch 404 ^/(?!err)
share|improve this answer
I kind of understand why you question the validity of using 404 in Redirect. Although only 301, 302, 303 and 401 status codes are listed, the manual also states that "Other status codes can be returned by giving the numeric status code" and "If the status is between 300 and 399, the URL argument must be present, otherwise it must be omitted". Your suggestion pertaining to creating of a separate document root works, but partially only, since css and other files would be 404ed. RedirectMatch produces same result as Redirect. – Question Overflow Sep 15 '12 at 3:23
Upon re-reading the manual, I also understand why my custom error doesn't work. Because there is a note saying "Redirect directives take precedence over Alias and ScriptAlias directives, irrespective of their ordering in the configuration file.". Therefore, the redirect would have occurred before my Alias can take effect. – Question Overflow Sep 15 '12 at 3:28
Would it be fine to just put the custom error pages within the document root to avoid using Alias or is there another way around? Thanks for trying to help :) – Question Overflow Sep 15 '12 at 3:37
@QuestionOverflow The problem isn't with the precedence of the Redirect, it's the fact that it applies to everything. Is there some reason the RedirectMatch rule that I've listed won't work for you? – Shane Madden Sep 15 '12 at 7:20
It did worked to the same effect as a separate document root actually. I should have substituted the err in the RedirectMatch with the actual Alias I used. Sorry for that and thanks for your help :) – Question Overflow Sep 15 '12 at 8:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.