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 Apache Virtual Hosts config currently has several repeats of this;

<VirtualHost *:80>

    DocumentRoot /home/

    LogLevel warn
    ErrorLog /home/
    CustomLog /home/ combined

    Alias /dev /home/
    ScriptAlias /cgi-bin/ /home/

How would one go about changing that so all the '' instances are replaced with whatever domain the user is currently viewing?

I know of mod_vhost_alias, but I don't see any mention of it being able to do logs or alias (aside from ScriptAlias) dynamically as well. Is there some way to accomplish that? I'd rather not sacrifice separate logs for this.

share|improve this question
up vote 1 down vote accepted

You could probably solve the alias with a mod_rewrite rule:

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

# remove www.
RewriteCond %{HTTP_HOST} ^www\.(.*)$ 
RewriteRule .? - [E=noWWWHost:%1]

# map /dev  to the documentroot for dev
RewriteCond %{REQUEST_URI} !^/~
RewriteCond %{HTTP_HOST} ^www\. 
RewriteRule ^/dev/(.*)$ /home/${lowercase:%{ENV:noWWWHost}}/dev/$1

# not using www
RewriteCond %{REQUEST_URI} !^/~
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^/dev/(.*)$ /home/${lowercase:%{HTTP_HOST}}/dev/$1

# make a log that is "splitable" on host
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

Edit: Forgot to add that the config above is untested :)

share|improve this answer

There are a couple of ways to go about this ... you can create a virtual host with a related log file for every host. If you are looking for wild card matching it may be easier just to parse the logs later with the given hostname.

share|improve this answer
What about Alias? I know there is VirtualScriptAlias, but I don't see any Alias equivalent. – Stephen Belanger Sep 30 '09 at 3:17

You can use mod_vhost_alias and change the log format by adding %V (Effective server name) at the beginning of the line.

Then you just have to write a simple shell script or perl program that will parse the raw log and write it to the relevant log file. You can even do it in real time using a piped log: CustomLog "|/path/to/" combined_vhost

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.