Virtual Directory or Alias in WebServers – IIS, Apache, Lighttpd

A virtual directory is a directory name (also referred to as path) that you specify in Internet Information Services (IIS) and map to a physical directory on a local or remote server. This name is most used for hosting websites in Windows Environment. For other Platforms the same as referred as Alias.

Why we need a Virtual Directory/Alias :
By default every webserver has its default location where you can place all the website files which needs to be hosted. In IIS its default website root directory is C:\inetpub\wwwroot\. But if you want to host the site from a different folder or path other than the C:\inetpub\wwwroot\ then we need a Virtual Directory and that can be mapped to any physical location of the directory. This will also helpful for shortening the path and you don’t want to expose the complete path of the location where your sites are hosted.

Configuring in IIS (6,7,8) :

IIS-Virtual Directory - Alias

IIS-Virtual Directory – Alias

http://localhost/ => When you access this Url from the Windows IIS, by default it shows you the IIS Welcome Page

Assume you have a Static Website in D:\Projects\Web\BookmarkMusic\Public\ and you want this to be hosted in IIS. Then you can create a Virtual Directory and provide the Alias as “MusicMarks” and enter the complete path in the Physical location textbox.

Now you can access the site http://localhost/MusicMarks/

Apache Web Server / Lighttpd :
Most of the Linux Webservers uses Apache/Lighttpd Webservers. Here the Virtual Directory is referred as Alias.But the same configuration applicable on Windows also.
To enable alias ensure the following line is enabled in the httpd.conf

LoadModule alias_module modules/mod_alias.so

And in the Node, add the following mapping

#For Web Servers running in Windows
Alias /MusicMarks D:/Projects/Web/BookmarkMusic/Public

#For Web Servers running in Linux Environment
Alias /MusicMarks /var/Projects/Web/BookmarkMusic/Public

Ensure to restart the Apache to see the changes. Now you can access using http://localhost:/MusicMarks/

Symbolic Link vs Alias :

How these Alias differs from the Hard/Symbolic Link is these alias are managed and redirected by the Webservers whereas the Symbolic Links are managed by the OS. You can also configure this functionality using Symbolic Links also. But its highly recommended to managed from the WebServer side so that it works when you migrate between systems.

Nirmal

Technical Geek - Gadget Enthusiast - Loves Programming C#,PHP & IOS - Blogger About

More Posts - Website

Follow Me:
TwitterGoogle Plus