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 have a fairly basic question. Please be patient with me.

As an example, say I host "" and "" on a single server with an ip address of "".

Here would be a typical apache configuration:

Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
# Other directives here

<VirtualHost *:80>
# Other directives here

How do I return a 404 error code for a request to "" without blocking all websites on the server?

Could you please include an example of an apache configuration directive I should be using?

share|improve this question
up vote 3 down vote accepted

First virtual host definition will be used as "catch all" in case if domain name in not known to Apache.

I know 2 solutions:

  1. Create one more <VirtualHost> pointed into empty folder and make it listed above all other virtual host definitions.

  2. Using mod_rewrite create a rule in first virtual host to return 404 response if %{HTTP_HOST} is an IP address.

Approach #1 is more logical and widely used. Approach #2 I would not use unless under some special circumstances.

share|improve this answer
I tried out solution #1. It worked as advertised. Thanks. – Kevin Jul 31 '11 at 23:31

The first defined virtual host will answer queries for the bare IP address. You can also just include a named virtual host for the IP address itself and point that at a directory with whatever you'd like to return in it.

share|improve this answer

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.