Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Let's say I have running on a server powered by Apache. It's the default virtual host.
Now someone has rewritten his hosts file to redirect to my server's IP. As my server doesn't know a thing about, it just resolves it to the default virtual host. So in this case get's resolved to and it tries to serve my site's /hello page. Is there a way (maybe with a RewriteRule or something) to disable requests requesting from my server? Give them a 403 for example or anything, just don't let anything through Apache unless it's requesting
I'm using the latest Apache version on Ubuntu LTS.

share|improve this question

3 Answers 3

Why is the default if you don't want it to be?

Add a new default virtual host that does nothing but return a 404.

Then add as a virtual host entry. It'll only get used if requested.

share|improve this answer

Why not simply change the default VHost to a deny one?

<VirtualHost *:80>
    DocumentRoot /var/empty/httpd
    <Location />
        Deny from all
        Allow from none

<VirtualHost *:80>
    ...your VHost goes here...
share|improve this answer

A RewriteRule would be something like this:

RewriteCond %{HTTP_HOST} !^your\.site\.com$ [NC]
RewriteRule .* - [F]

Other solution would be to add a new default Virtual Host which responds with 403 to any requests.
Only matching requests would then go to your real Virtual Host.

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.