Use Alias and Apache to Create Custom Mappings

I really love the flexibility Apache gives you when setting up virtual hosts. Another benefit is the Alias directive.

I've worked on a few concepts recently that I want to demo as a sample app. After a few revisions, I finally settled on a folder structure and Alias name setup I felt would secure my component classes and facilitate mappings to frameworks and shared libraries.

Here is the folder structure (note that application names are obfuscated to protect the innocent):

/apps
/apps/appName
/apps/appName/config
/apps/appName/controller
/apps/appName/layout
/apps/appName/model
/apps/appName/root
/apps/appName/view
/coldspring
/lightwire
/com

Here is the Apache virtual host configuration (somewahat abridged):

<VirtualHost 127.0.0.1:80>
DocumentRoot "/path/to/apps/appName/root"
ServerName appName.fancybread.com
DirectoryIndex index.cfm
ErrorLog logs/appName-error_log
CustomLog logs/appName-access_log common
# application alias settings
Alias /config "/path/to/apps/appName/config"
Alias /controller "/path/to/apps/appName/controller"
Alias /layout "/path/to/apps/appName/layout"
Alias /model "/path/to/apps/appName/model"
Alias /view "/path/to/apps/appName/view"
# framework and shared library mappings
Alias /lightwire "/path/to/lightwire"
Alias /coldspring "/path/to/coldspring"
Alias /com "/path/to/com"
Alias /lib "/path/to/lib"
</VirtualHost>

As you can see, using Alias within the virtual host setting provides the flexibility reconfigure applications with a change to the mapped path. So for cats who still prefer to type their objects, as I do, this is a blessing.

I work in a mixed environment where the production server is IIS and dev is Apache. I hope I can create the same setup with IIS virtual directories. Anyone soing this sort of thing in IIS? Am I in for a rude awakening?

Comments
Aaron Roberson's Gravatar Glad you blogged about this Paul. I actually use a virtual host which points to the app root and the use aliases within the vhost to access different directories beneath it. Just a preference.

-Aaron
# Posted By Aaron Roberson | 5/18/07 12:29 PM
rich's Gravatar You can have virtual servers and virtual directories (aliases) in IIS too, just be prepared to do a lot of pointing and clicking. I've come to prefer Apache's simple conf file...plus I can keep it in source control and deploy with releases.
# Posted By rich | 5/18/07 12:48 PM
Paul Marcotte's Gravatar @Aaron, sounds like we're pretty much doing the same thing, I've decided point my web root to the root folder and Alias back one folder to my components so that app specific components will be grouped in the app folder.

@rich, nice to know. I sustpected it would be basically the same process using a gui. I agree that the Apache config process is clearer and easier (once you've worked with it for a while).
# Posted By Paul Marcotte | 5/19/07 2:40 PM
Trond Ulseth's Gravatar I love it when I google something and end up finding the solutions on a fellow CF developers blog even when it's not strictly CF related. This happens all the time. Shows me that the CF community is a knowledgeable crowd and over average willing to share their wisdom :)

Thanx for the post.
# Posted By Trond Ulseth | 4/4/08 9:38 AM
Paul Marcotte's Gravatar My pleasure! :)
# Posted By Paul Marcotte | 4/4/08 7:52 PM
S. Ural's Gravatar Assume I have 2 servers: Server 1 and Server 2 and I will define the alias in Server 1's conf file.
How can I define this alias for a directory which is on Server 2 with some IP
# Posted By S. Ural | 5/17/08 4:15 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner