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

My website's two major sections can be accessed using:

  • for general content

  • for more specific content

The laptop section is ready and deployed. User can access it directly. Also, search engines have started crawling and indexing it.

BUT, the general content is not ready; it will not be for few months.

As of now, there is no document root or files in the server for www and there is no virtual host tag for it.

Content of httpd.conf:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /path/to/website/subdomain/root
    <Directory /path/to/website/subdomain/root>
        AllowOverride All
        Allow from all

There is no other virtual host tag in there.

In my domain registrar control panel, I have added an A Record for the subdomain laptop and pointed it to my server IP. There are two other entries - @ and www both pointing at my IP. I am unable to edit/delete the www entry.

I thought that is all that is needed to prevent access to www. But it is not working!

When users type, they are taken to I don't want this to happen. Just some default browser error message like Server not found or Page not found should be shown.

How can I achive this?

One Solution: I added the following to end of httpd.conf

<VirtualHost *:80>

Notice there is no document root! It worked. I am getting a 404 if I visit or And the subdomains are working just fine.

I don't think this is an elegant method. Still waiting for a better/proper way to do it.

share|improve this question
Any global DocumentRoot will be inherited; this is generally not what you want. Set the DocumentRoot to something innocuous, like /tmp. You also don't seem to understand what ServerName does; set your Servername to, and remove the ServerAlias. – adaptr Jan 11 '13 at 15:36
@adaptr I changed the ServerName part. Also, if I set the DocumentRoot to /tmp or some other folder, then I am seeing the Apache Test Page instead of a 404. Is it possible to avoid that? – user150932 Jan 11 '13 at 16:25
First, remove the ServerAlias. You don't need it. Second, that is likely some distro's defaulit rewrite kicking in; find it and remove it. – adaptr Jan 14 '13 at 9:39

ServerName should be equal to the full domain name including the sub-domain laptop. Otherwise, the whole content will be reachable.

You may then create a block for the ServerName and a other one with with an authentication forced (users won't have the access unless they have the password) which block also google crawling. Or disabling totally when you use only

Users go to when they go to because by default the content of is served for ServerName which includes and They would have the same content as long as both www and laptop are in the DNS.

ServerAlias is only when more than one domain name have to be redirected to the content defined in the block VirtualHost. For example, if you have laptop1 and laptop2 in the DNS and you want the same VirtualHost being applied for both.

Hoping this solves the issue you're having ...

EDIT to answer your comment:

I would have this in my config file:


ServerName laptop
ServerAlias laptop
DocumentRoot /var/www/laptop


And then, if I want another content to be applied for a second VirtualHost named www, I would add a second paragraph similar to this one, but with different ServerName, ServerAlias, DocumentRoot. I just wanted to explain that you can do that with an authentication to make sure during development process you are the only one to access your VirtualHost

share|improve this answer
I added the full subdomain in ServerName like you suggested. Didn't work by itself. But I am not sure what you are suggesting in second paragraph. Are you asking me to add some content for www, add a virtual host tag for it, then add authentication to prevent access to it? – user150932 Jan 11 '13 at 13:34
I have edited my answer to be able to put some code inside – philippe Jan 11 '13 at 14:49
Oh I understand. But I forgot to say that, it will be months before even test content for www will be uploaded to the production server. I will also not be accessing it during this time. I just want to make it as if simply didn't exist. – user150932 Jan 11 '13 at 15:01
Ok, then simply add only one block for laptop and nothing for www. Anyway, is this configuration working, I mean, is your www disabled when trying to access – philippe Jan 11 '13 at 16:27

Your Answer


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