In this post, you will learn how to set up a domain alias for the purposes of pointing a domain to your local server files. This is useful so that you can develop a website locally before deploying it to a live server. We used a domain alias when developing the new design for Pligg.com so that we could test for broken URLs that might occur due to many large changes to the site structure. Below is a video guide that you can follow along with demonstrating how to set up a domain alias, or you can read the full article for step by step directions.
We begin by opening up the httpd.conf file, which is responsible for configuring Apache. You can do this by left clicking on the WAMP taskbar icon and then select Apache > httpd.conf to open the file in a text editor. Alternatively, you can navigate to the directory on your computer where this file is stored. For me, the file was located at C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf.
Within the httpd.conf file, find the following lines:
# Virtual hosts #Include conf/extra/httpd-vhosts.conf
Remove the pound symbol (#) from the beginning of the second line referenced to un-comment it. This will call the httpd-vhosts.conf file, which is used in the next step. Save the document and close it. You will now edit the httpd-vhosts.conf file, which was located at C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf.
Begin by changing the line:
Next you need to add a couple blocks of code to the bottom of the httpd-vhosts.conf file. Copy/paste the following code to the bottom of the file, changing the value for DocumentRoot and Servername so that they point to your website files and domain.
<VirtualHost *:80> DocumentRoot "c:/wamp/www" ServerName localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "c:/wamp/www/domain-files" ServerName demo.com </VirtualHost>
The last 4 lines represent the code needed to associate Apache with your domain and tells it where the domain files are stored. Duplicate these lines and edit them to add other domains. When you are finished editing the file, save it and restart Apache. You can do this by left-clicking on the WAMP taskbar icon, then select “Restart all services”. The WAMP icon should turn orange, red, orange, then back to green when it has started up again.
Finally we need to add the new domain to the Windows hosts file. This change will make it so that when you type in the domain into your browser (or any other service like SSH/FTP) it will direct to your local computer rather than the IP address that is normally associated with the domain. Windows makes it pretty easy to add new domain configuration lines to the file, but unfortunately opening the file isn’t so easy.
In order to edit the hosts file, you will most likely need to open up a text editing program like Notepad with Windows administrator permissions. To do that, right click on Notepad and choose “Run as administrator”. This will prompt you for permissions, which you must approve before it launches the program.
Next you will need to open the hosts file from Notepad’s Open dialog. Luckily, the file is typically in the same directory for all Windows users: C:\Windows\System32\drivers\etc\. By default Notepad only displays files with .txt file extensions in directories, so click on the “Text Documents (*.txt)” dropdown menu and select “All Files (*.*)”. This will let you see several files stored in the directory, and you should now be able to open the “hosts” file.
127.0.0.1 localhost 127.0.0.1 demo.com
Make sure that there is an entry for localhost, and add in your own domain entry like the example above. When you are finished, save the hosts file and open up the domain in your browser. If you have previously visited the domain in your browser you may need to refresh the page a couple times before the changes take effect.
From here you are good to go, and you should be able.