In a previous post we touched upon the Alias statement in your VirtualHost directives. An Alias is a way of defining a virtual directory for your site. This is a pretty common practice in the web world. Your site code may be stored in your site's root (wwwroot) folder, but you may want to store your assets (images, video, stylesheets, etc.) outside your webroot. You might even want to store them on another server altogether. You'll want to access these items as if they're part of your site, like http://username.companyname.loc/Images/mypic.jpg or http://username.companyname.loc/Media/myvideo.flv.

Defining an Alias is easy, when dealing with your local file system. An Alias that points to a UNC path, in Windows, is another story. You have to use a UNC path because Apache will not allow you to utilize a mapped drive (it'll crash Apache, at least under 2.0). What took me a while to figure out was that you can not use Apache to control the directory access (as in permissions), you must do this through the user account access. You can not use the Directory Apache directives for access control. This also means that your Apache instance must run as the user who has access to the remote resource (I also setup CF instance to run as the same user).

I also discovered something else the hard way, Apache Aliases are case-specific. This means that you have to use double Aliases for each virtual directory that you define via an Alias. Remember, this is Windows, so code can go either way. You'll want to plan for either eventuality.

In our last post we defined a 'sites' instance, for the display of a mythical, templated application system. So, imagine that each site of that system would require it's own VirtualHost directive. Each one, though, would also be using shared media resources from the same location outside the webroot, like on a media server. For this, you can create another include in your Apache conf folder - site_aliases.conf, within which you could singularly define your remote virtual directories:

view plain print about
1Alias /Images/ //remote-serv1/Inetpub/wwwroot/Images/
3Alias /images/ //remote-serv1/Inetpub/wwwroot/Images/
5Alias /Video/ //remote-serv1/Inetpub/wwwroot/Video/
7Alias /video/ //remote-serv1/Inetpub/wwwroot/Video/
9Alias /Styles/ //remote-serv1/Inetpub/wwwroot/Styles/
11Alias /styles/ //remote-serv1/Inetpub/wwwroot/Styles/
13Alias /SiteSpecific/ //remote-serv1/Inetpub/wwwroot/SiteSpecific/
15Alias /sitespecific/ //remote-serv1/Inetpub/wwwroot/SiteSpecific/

Once you've defined these remote shared resources, you can then Include them in your site definitions in your VirtualHost directives:

view plain print about
2    ServerAdmin
3    # Root folder for, in the 'sites' instance
4    DocumentRoot "C:\Documents and Settings\username\My Documents\wwwroot\siteroot"
5    ServerName *.thisdomain.loc
6    # SGB [072007]: shared Alias Include
7    Include conf/site_aliases.conf
8    ErrorLog logs/thisdomain.loc-error.log
9    CustomLog logs/thisdomain.loc-access.log common
10    # SGB [072007]: Add include for the 'sites' ColdFusion instance
11    Include conf/cf_sitesinstance.conf

Once you've restarted your Apache instance you will be able to access these resources as part of the domain.