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

I'm new to Apache, and I'm wondering if there's a way to configure VirtualDocumentRoot to create an exception for just one of my vhosts on my local server. Currently all of my sites are stored in folders with the convention sitename.dev. In httpd.conf I'm dynamically setting VirtualDocumentRoot based on the server name:

# get the server name from the Host: header    
UseCanonicalName Off

LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /path/to/logs/access.log vcommon
ErrorLog /path/to/logs/errors.log

VirtualDocumentRoot /path/to/vhosts/%0

This works great for all of my sites with one exception... the document root for one of the sites should point to exception.dev/src/php instead of just exception.dev.

According to the answer I found here, it sounds as if VirtualDocumentRoot cannot be set based on a conditional. So I was hoping my problem could be resolved by setting an alias of some sort to point exception.dev to the right directory.

I've tried adding VirtualScriptAlias, but this prevents the Apache server from starting:

VirtualScriptAlias /path/to/vhosts/exception.dev /path/to/vhosts/exception.dev/src/php

I've also tried the same type of thing with ScriptAlias and just Alias, but still no luck.

Is there something I'm missing here? Or is what I'm trying to do impossible? Any help would be greatly appreciated!

Oh, and if it helps, here's my output if I run httpd -S:

httpd: Could not reliably determine the server's fully qualified domain name, using XXXXX.local for ServerName
VirtualHost configuration:
Syntax OK

UPDATE: I got this to work by modifying Shane's answer below as follows:

NameVirtualHost *

<VirtualHost *:80>
    ServerName exception.dev
    DocumentRoot /path/to/vhosts/exception.dev/src/php
</VirtualHost>

<VirtualHost *:80>
    ServerName default
    ServerAlias *.dev
    VirtualDocumentRoot /path/to/vhosts/%0
</VirtualHost>
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Have a virtual host with your "normal" config, the VirtualDocumentRoot, and another with the exception config.

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName default
    ServerAlias *.dev
    VirtualDocumentRoot /path/to/vhosts/%0
</VirtualHost>

<VirtualHost *:80>
    ServerName exception.dev
    DocumentRoot /path/to/vhosts/exception.dev/src/php
</VirtualHost>
share|improve this answer
    
thank you so much! i got this to work with two small tweaks: added an asterisk after NameVirtualHost *, and moved the exception config below the default config within httpd.conf. will post the updated code above. –  luke Mar 21 '13 at 4:54
    
@luke Do you mean below or above? Your edit has the exception above - that's potentially a problem because it will be used for any hostnames that don't match a configured ServerName or ServerAlias (like if you had subdomain.somedomain.dev). –  Shane Madden Mar 21 '13 at 5:03
    
You're right, that was a typo - meant to say that I placed the exception config above. Would that potential issue be resolved if I changed the default ServerAlias to * instead of *.dev? For whatever reason I'm just unable to get exception.dev to work unless it's placed above the default config. –  luke Mar 21 '13 at 17:54
add comment

Your Answer

 
discard

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.