RewriteEngine on RewriteMap lowercase int:tolower # allow CGIs to work RewriteCond %{REQUEST_URI} !^/cgi-bin/ # check the hostname is right so that the RewriteRule works RewriteCond ${lowercase:%{SERVER_NAME}} ^www\.[a-z-]+\.isp\.com$ # concatenate the virtual host name onto the start of the URI # the [C] means do the next rewrite on the result of this one RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C] # now create the real file name RewriteRule ^www\.([a-z-]+)\.isp\.com/(.*) /home/$1/$2 # define the global CGI directory ScriptAlias /cgi-bin/ /www/std-cgi/