Create an Alias with WAMP


Creating an alias with WAMP server appears quite simple but it will probably require a few more steps then what first appears.

What is an Alias

An alias in regards to WAMP server means pointing to a folder in one location and maping that folder to a virtual folder in WAMP. For example, lets say you have WAMP setup in its default location under "C:\wamp\www" but you want to maintain some client web sites that require WAMP in a separate folder called "clients" located on your "D:\" drive in a folder called "clients". In order to cover this scenario you would create an alias that tells WAMP or the Apache server to look for files in one location but output them as if they were in a folder relative to the server root directory.

How to Create an Alias

For this tutorial I will make an alias called "clients". The alias will point to a folder called "clients" located on a drive with the drive letter of "D:\".

First step is to make an Alias from within WAMP. To do this launch WAMP, click on the WAMP icon located in the system tray. Next hover over "Apache" and then hover over "Alias directories". From there click on "Add an alias".

When you click on the "Add an alias" menu item a command prompt window will open asking you to create an alias. In this case I want to create an alias called "clients", so I will enter "clients" into the command prompt window and then press "Enter".

Next the command prompt will ask you to enter the destination of your alias. This is the folder where you will be storing the folders. In this case I will be using a folder called "clients" located on the "D:\" drive, so I will enter "d:/clients" into the command prompt. Once you do this it should say "Alias created. Press Enter to exit". Press "Enter" to exit. It will look like all went well and that you can now use the alias. This is not the case, and we will need to make a couple of small tweaks to get this to work.

Tweak Number 1 (Mandatory)

To get our alias to work we need to edit the "httpd.conf" file. We can access this file from the system tray by clicking on the WAMP icon and then clicking on "Apache". From there you will see the "httpd.conf" file listed. Simply click on this file to edit it.

The httpd.conf file should open in a text editor (in my case it opened in Notepad). Do a search for for "DocumentRoot". Once you found that area of the document scroll down a bit further until you see something similar to the following.


<Directory />
    AllowOverride none
    Require all denied
</Directory>

Once you have found that area you will need to enter in the following code after the code shown above. Replace "d:/clients" with the path you set when you created the alias.


<Directory "d:/clients">
    AllowOverride none
    Require all granted
</Directory>

After you have entered in the code above. Simply save the file and close. You should now restart WAMP. Once WAMP has restarted you should now be able to access your alias by navigating to "localhost/{{ your alias name }}/", in my case it would be "localhost/clients/. Don't forget the trailing slash. If you want to be able to write the URL without the trailing slash then see the tweak below.

Tweak Number 2 (Optional)

If you want your alias to work both with and without a trailing slash. For example if you want to enter either "localhost/clients/" or "localhost/clients" (without the trailing slash). Then you will need to make a small edit to the alias.

To edit an existing alias, click on the "WAMP" icon in the system tray, then click on "Apache", then "Alias directories". Once inside the "Alias directories" menu hover the alias you want to edit then click on "Edit alias".

Once you do this a text file should open with the code for your alias. Simply remove the trailing slash from the alias's name (In my case I would be changing "/clients/" to "/client") and then save the file, close the text editor and restart WAMP. Now you should be able to navigate to your alias without the trailing slash.

If you want to automate this process so that your alias just work without the trailing slash then give the article WAMP Alias Directories by Will Anderson a read.