Use Alias and Apache to Create Custom Mappings

Apache , Configuration Add comments
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?

7 responses to “Use Alias and Apache to Create Custom Mappings”

  1. Aaron Roberson Says:
    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
  2. rich Says:
    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.
  3. Paul Marcotte Says:
    @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).
  4. Trond Ulseth Says:
    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.
  5. Paul Marcotte Says:
    My pleasure! :)
  6. S. Ural Says:
    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
  7. Matthieu Says:
    Funny, I was googling some java things and saw your website on the first page :) Congrats Paul. I hope all is fine.

Leave a Reply



Powered by Mango Blog. Design and Icons by N.Design Studio