Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a virtualhost that is forwarding to my main domain (e.g. showing the same content that my main domain shows).

Right now my site uses a main domain: www.example.com

And various alias domains: example.com short.com

I'm creating a new walled garden development site: dev.example.com

But my virtualhost isn't being recognized for that url.

Do I have to create a wildcard record for *.example.com in my DNS host or something?

Here is the pertinent section from my default virtualhost settings (currently in /etc/apache2/sites-enabled/000-default ):

<VirtualHost *:80>
   ServerAdmin webadmin@example.com
    ServerName www.example.com
    ServerAlias example.com
    ServerAlias shortUrlEx.com
    ServerAlias www.shortUrlEx.com

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]

    RewriteCond %{HTTP_HOST} ^shortUrlEx.com [NC]
    RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]

    RewriteCond %{HTTP_HOST} ^www.shortUrlEx.com [NC]
    RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]

    DocumentRoot /var/www/examplepath
    php_value date.timezone "America/New_York"
    php_value expose_php "Off"
    php_value upload_max_filesize 10M
    php_value post_max_size 10M

... other config options

And dev.example.com is configured as follows (from /etc/apache2/sites-enabled/dev.example.com):

<VirtualHost *>
<Directory />
    AuthType Basic
    AuthName "Check Site"
    AuthUserFile /srv/dev-example/config/.htpasswd
    Require valid-user

    ServerName dev.example.com

    DocumentRoot /srv/dev-example/public_html/
    Alias /favicon.ico /srv/dev-example/docs/dev_favicon.ico
    php_value date.timezone "America/New_York"

    php_value expose_php "Off"
    php_value upload_max_filesize 10M
    php_value post_max_size 10M
    <Directory />
        Options FollowSymLinks -Indexes
        AllowOverride None
    <Directory /srv/dev-example>
        Options FollowSymLinks MultiViews -Indexes
        AllowOverride All
        Order allow,deny
        allow from all

    ... further options that shouldn't be applicable...

What am I doing wrong here? How should I configure the default and dev.example.com virtualhosts to allow access to the dev subdomain and use the main domain for everything else?

share|improve this question
Did you run a2ensite for the dev domain? Have you restarted apache? –  EEAA Jul 6 '11 at 20:55
I have indeed restarted apache. a2ensite I haven't heard of before, so I expect no. I am wondering whether I have to set up a wildcard subdomain with the DNS or whatever. Not sure what is best practice there. –  Kzqai Jul 6 '11 at 21:00
Ah, a tool for creating the symlink in the /etc/apache2/sites-enabled/ directory, yeah, I've got a manually created symlink in there that maps to the latter config. –  Kzqai Jul 6 '11 at 21:01
when you do a DNS lookup for dev.example.com, are you getting the correct response? If you have not setup wildcard DNS or created an entry specifically for dev.example.com, you would need to put the entry in your hosts file to test. –  micah Jul 6 '11 at 21:13
Yeah, I should have specified that going to the url shows the same result. Hell, I'll just put the url in the question. I updated the question to explain that the same result is being displayed for dev.shermanbrothers.com and shermanbrothers.com –  Kzqai Jul 6 '11 at 22:06

4 Answers 4

What happens when you attempt to ping "dev.example.com"? Does it resolve to an IP address at all? If so, is it the IP address of the Apache server?

In this case, I suspect you will need to configure a new "dev.example.com" record in DNS (or at least in /etc/hosts) so that your workstation knows where that DNS is supposed to go.

share|improve this answer
Sorry, should have clarified that it it showing the same content as example.com. I'll add the dev url to my hosts and see what happens. –  Kzqai Jul 6 '11 at 21:23
No difference if it's in my hosts file pointed at the server's ip address. –  Kzqai Jul 6 '11 at 22:04
Yeah, I just put the site back into my question, easier that way. (It's dev.shermanbrothers.com and shermanbrothers.com). –  Kzqai Jul 6 '11 at 22:10
I'm just taking a wild stab at this, but is it possible that the RewriteConds are taking effect before the virtual host does, and rewriting "dev.shermanbrothers.com" back to "www.shermanbrothers.com"? –  Handyman5 Jul 6 '11 at 22:13
I don't believe so because I have to specifically add each and every domain (annoyingly). Perhaps it's a problem with that default virtualhost being met first, though. Not sure of what slick way to solve it that is. –  Kzqai Jul 6 '11 at 22:23

Try updating your dev site's Virtualhost entry to: <VirtualHost *:80>

Note the addition of the :80.

Your virtual host definitions should match the NameVirtualHost setting's value. Running apachectl configtest usually reports any mismatchs.

share|improve this answer
Looks like I had to specify the url in the virtualhost as per: <VirtualHost dev.shermanbrothers.com:80>`, but it was indeed messing with the virtualhost line that solved it. –  Kzqai Jul 7 '11 at 19:59
Whoops, I was wrong, that password-protected the main site as well. –  Kzqai Jul 7 '11 at 20:04
up vote 1 down vote accepted

I had to:

Change the virtualhost setting to be:

<VirtualHost *:80>

Uncomment the NameVirtualHost setting:

NameVirtualHost *:80

And add a ServerAlias to the dev.shermanbrothers.com virtualhost.

ServerAlias dev.shermanbrothers.com
share|improve this answer
Note that apache 2.4 requires .conf on the end of virtualhosts for them to work, which is what caused me the problem a second time. Found the documentation for the change in: vi /usr/share/doc/apache2/NEWS.Debian.gz –  Kzqai Aug 6 '13 at 21:49

Shouldn't /etc/apache2/sites-enabled/dev.shermanbrothers.com be /etc/apache2/sites-enabled/dev.shermanbrothers.com.conf? I think Apache takes *.conf files, at least it does in CentOS. Or have you included it manually?

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.