Step by Step Instructions to Assign Multiple Virtual Domain Names and Websites to Your Localhost
With the help of this tutorial you can assign a virtual domain name to your localhost.
You can access your local website with your favourite name like http://mysite.web instead of http://localhost and also you can assign different virtual domain names to different local webistes.
Requirements:
• Apache webserver installed. It would be nice if you have WAMP server. This tutorial is based on WAMP server. But it works on any Apache server.
Procedure:
Part 1:
1. First go to location "C:\WINDOWS\system32\drivers\etc" directory.(or where you installed windows).
Then open "hosts" file with simple text editor like notepad.
2. You'll see "127.0.0.1 localhost" at the end of the file.
In the next line add your virtual domain name like the example shown below.
Here mysite.web is just my example. You can use anything you like.
127.0.0.1 mysite.web #this is virtual domain name.
3. Now save the hosts file. mysite.web is just an example. You can add anything like mywebsite.local and you can use any extension or no extension at all.
You can simply add mysite also.
4. Now test your virtual domain. Just type "http://mysite.web" You must see your wamp page or webservers defalut page. If not go through the process again.
NOTE: Don't use any real domain name like www.google.com or your own domain name if you have any. If you did so, you cannot that access the original remote site. This is because, 127.0.0.1 is loopback address, anything with that address will never leave your computer.
Part 2- Now some difficult part. Assigning this virtual domain name to your web site in your local server.
1. Open your httpd.conf file in conf directory of Apache webserver folder.
If you are using WAMP click on WAMP icon, go to Apache menu and select httpd.conf there.
2. Create a new folder mysite in your C:\>. And create a new page index.html. These are for testing purposes.
If you have a local website, specify the full path of website in below code.
3. Now add the following code at the end of the httpd.conf file.
NOTE: PLEASE TYPE IN THE CODE MANUALLY without comments, DON'T COPY AND PASTE.
NameVirtualHost 127.0.0.1
ServerName localhost
DocumentRoot "C:/wamp/www" #this is default wamp root for websites,
ServerName mysite.web #your virtual domain name
DocumentRoot "C:/mysite" #location of your site, no extenison needed.
Order Allow,Deny
Allow from all
Save this file. Restart your WAMP server. Now type http://mysite.web You'll see the index page of mysite.
If you want another website, first add another virtual domain in hosts file as shown in part1.
And then copy and paste the following code at the end of httpd.conf file. Just change the virtual domain name, and locations of website.
ServerName mywebsite.web #change this virtual domain name
DocumentRoot "C:/mywebsite" #location of your site, change this.
Order Allow,Deny
Allow from all
You can add as many websites as you wish. Just repeat the above procedure. And access all your local websites with your favorite name. It will be fun and will save lot of your time.
No comments:
Post a Comment
Mayur Raiyani