A virtual directory allows you to serve up a file or series of files from any area of the system's hard drive.
Many professionals refer to a virtual directory as an alias. From a technical standpoint, a virtual directory allows a Web server to map a URL path name (seen in the browser) to a local file (seen as you access the hard drive locally, say through a file management program) anywhere on the hard drive. Some of the advantages of the flexible mapping of URL path names to local file names include:
Advantage
Explanation
The ability to serve files that do not reside immediately beneath the Web server root directory
Most Web servers require that all files be located directly beneath the Web server root. However, a virtual directory allows you to include any local file or folder into the Web server directory structure, regardless of its location. You can establish a virtual directory on another system, if you wish.
Simplified organizational structure
Instead of having to locate all files and folders beneath the Web server root, an administrator can arrange files on disk at his or her discretion.
Cleaner URLs
Although this is a minor issue, the URL shown in the viewer's browser reflects the site's organization, enhancing the viewer's ability to navigate and enjoy the site.
Virtual Directory
The following series of images below is designed to show you how a virtual directory allows you to access files from any location on the hard drive. It starts by showing you how a Web server searches for documents by default, then shows how you can implement a virtual directory solution.
Aliases and virtual directories
1) Suppose that you want your web server to present a collection of documents called doc1.html and doc2.html. They are located in the systemroot\home\sales\docs directory.
The diagram illustrates a folder structure and provides instructions for configuring a web server to map a URL path to a local directory.
Diagram Breakdown:
Folder Structure:
The hierarchy displayed in the image shows folders and files under a directory system.
Key folders include:
systemroot
home
sales
docs
doc1.html
doc2.html
inetpub
wwwroot
URL Mapping Requirement:
The goal is to make the sales/docs folder accessible via the web URL:
http://www.yoursite.com/sales/doc1.html
The local path of doc1.html is:
systemroot\home\sales\docs\doc1.html
This means that users visiting the above URL should be directed to the corresponding local file path.
Configuration Instruction:
To achieve this, the web server must be configured to map the URL:
http://www.yoursite.com/sales/doc1.html
to the local file system path:
\home\sales\docs\
This typically involves setting up a virtual directory or an alias in the web server configuration.
Key Takeaways:
The image visually explains how a local directory path should be mapped to a web-accessible URL.
This setup allows users to access files stored in a specific folder via a browser.
Proper configuration is required on the web server to handle this mapping.
2) Make this folder accessible to users under the URL https://www.anycompany.com/sales/doc1.html.
3) If you do not make these folders accessible, the web servers would attempt to satisfy the web browser's request by looking for the directory \Inetpub\wwwroot\sales\docs\.
4) Using a virtual directory solution, the doc1.html and doc2.html files reside in the systemroot\home\sales\docs directory and are accessed by www.yoursite/sales/docs1.html
5) Using a virtual directory solution, the doc1.html and doc2.html files now reside in the systemroot\home\sales\docs directory and are accessed by the same URL
In the next lesson, we will discuss virtual servers.