Working With Apache’s Alias Directive

July 7th, 2008 · No Comments

Apache Directory Alias TutorialA couple of weeks ago, I’ve post a series of tutorials on How To Install Your Own Web Server on Windows with Apache, PHP and MySQL. Today I’m going to sort of pick up where these tutorials left by introducing you to Apache’s Directory Aliases.

While it may not be necessary for you to read all the previous posts, they may provide you with a better understanding of Apache’s HTTPD Server.

An Introduction To Apache’s Alias Directive

From Apache’s HTTPD Server perspective, a directory alias allows documents to be stored in the local filesystem other than under the DocumentRoot. This is set using the Alias directive. So for example, you could have the following directory structure:

  • c:\www\mywebsite - The document root of your website
  • c:\downloads - Contains downloadable files

In this case, the content of c:\www\mywebsite will automatically be published on the web as it is your website’s root folder by default (ie.: http://mywebsite/). On the other hand, c:\downloads will not be available as it sits outside of c:\www\mywebsite.

Let’s see how we can make the content of the c:\downloads available publicly as if it was a subdirectory of c:\www\mywebsite. And not only do we want it to be available publicly, we want to access it as if it were named files and not downloads. So after we’re done, we should be able to access the content of c:\downloads through this URL:

http://mywebsite/files

You following me? Great.

For this tutorial, I am using a WAMP setup which means Windows-Apache-MySQL-PHP. Apache’s configuration files are located in C:\Apache2\conf. My website VirtualHost entry in c:\Apache2\conf\httpd.conf actually looks like this:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin info@thewebhostinghero.com
    DocumentRoot "C:/www/mywebsite"
    ServerName mywebsite
    ErrorLog logs/mywebsite-error_log
    CustomLog logs/mywebsite-access_log common
</VirtualHost>

First we’re going to add an Alias directive to our VirtualHost entry:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin info@thewebhostinghero.com
    DocumentRoot "C:/www/mywebsite"
    ServerName mywebsite
    Alias	/files	"C:/downloads"
    ErrorLog logs/mywebsite-error_log
    CustomLog logs/mywebsite-access_log common
</VirtualHost>

Then we need to specify the permissions for this directory. We’re going to add a Directory entry right after the VirtualHost one:

<Directory "C:/downloads">
  Options +Indexes
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

Now put some files into c:\downloads and restart the Apache service. Open your web browser to http://mywebsite/files and you should now see the content of the directory:

Apache Alias Tutorial

Of course, this is not an in-depth tutorial on Apache’s Alias directive so here are a few useful links:

Feel free to ask any questions through the comments!

0 responses so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment




Posted in Apache · Tutorials | No Comments

Dedicated Servers
 
VPS
Website Hosting
 

Recent Comments

Recent Webmasters

Hosting Type :
Monthly Price :
Storage :
Transfer :
Sort By :
Search