Solved

On WAMP I need to redict each url specified in hosts file to a different localhost subfolder. How do I do it?

Posted on 2014-07-23
2
1,399 Views
Last Modified: 2014-07-24
Hi all,

I use WAMP on Windows 7. In my localhost folder I have serveral sites and I would like to set several urls in the /etc/hosts file to ridirect me to different localhost folders.

Eg. I have already set the domain "www.mysite.com" to 127.0.0.1 in the hosts file.
Now when I type "http://www.mysite.com" I get redirected to the main localhost index/welcome page of WAMP.
However I have a folder called "mysite" and I would like to be redirected to that folder and not the localhost root.
I tried to edit the httpd.conf file by adding
Redirect permanent /mysite http://www.mysite.com
But this does not seem to work. I have also restarted wamp several times after having made this change.
Under my Apache the mod_alias is already on.

Could anyone suggest a working solution?

I have several sites and I need each one to be redirected to a localhost subfolder.

thanks in advance
0
Comment
Question by:badwolfff
  • 2
2 Comments
 

Accepted Solution

by:
badwolfff earned 0 total points
Comment Utility
I found the answer here and I am sharing it for all other users:

http://www.trailheadinteractive.com/creating_multiple_virtual_sites_a_single_apache_install_windows_xp


Creating Multiple Virtual Sites on a WAMP Server Installation

When developing multiple sites, it is helpful to have a copy of each site running on your local computer.  With Apache it is fairly easy to configure multiple sites under one install.  This article outlines the basic steps for configuring Apache's "Named Virtual Hosts" feature under WAMP Server on Windows XP.
Step 1: Tell your machine to answer to different names.

By default, Windows will answer to the name "localhost" for browser requests originating on the same machine (yours). If you have WAMP Server running, you can browse to http://localhost and see your WAMP site.  We can make Windows answer to multiple names by editing a file called "hosts" located in your /windows/system32 folder.  Browse to:

"C:\windows\system32\drivers\etc"

Once there, you should see a file titled "hosts".  Open that file with a text editor like notepad or Komodo Edit.  You may have to change the open dialog to "all files" in order to see it.  You should see a line that looks like this:

127.0.0.1        localhost

That tells Windows that the name "localhost" points to the machine who's IP address is 127.0.0.1, which is a standard address for "this machine".  We can multiple entries for 127.0.0.1, and your browser will then associate all of them with your local computer. In our case, let's create one called "client1.localhost".  Add a line to the hosts file so it looks like this:

127.0.0.1        localhost
127.0.0.1        client1.localhost

You can add as many entries as you like and your browser should display your WAMP Server site for all of them.  Save your hosts file and try visiting http://client1.localhost" in your browser.  You should see your WAMP site.

Note: Do not create hosts entries for external sites.  This can cause hours of frustration and needless troubleshooting.  For example, if you added this line:

# Don't do this.
127.0.0.1        google.com

You would no longer be able to access google.com, because it is now associated with your local computer.  The request never reaches the Internet. The same applies to client domains.  For this reason, stick to something identifiable as local, like "google.localhost".
Step 2: Create a Client Site Folder

We need multiple site root folders to house multiple sites. Currently WAMP Server only has one site root, which typically lives at "C:\wamp\www".  Let's create another one at "C:\wamp\client2".  Navigate to "C:\wamp", and click "File -> New -> Folder".  Rename your new folder to "client2".

Create a test file called "index.html" in "C:\wamp\client2":

<html>
<head>
<title>Hello?</title> 
</head> 
<body>
Hello from Client 2! 
</body>
</html> 

Step 3: Tell Apache to Serve Multiple Sites by Name

WAMP configures Apache to serve a single site that usually lives in "C:\wamp\www".  Apache can handle multiple sites if we tell it where to look.  To open your WAMP Server Apache configuration, left-click the WAMP Server icon and select "Apache -> httpd.conf".  The file should open in notepad.

Look for a line like this:

Listen 80

This tells Apache to listen for browser requests on port 80.

Change it to this:

Listen *:80 

This tells Apache to listen to port 80 of any address.

At the end of httpd.conf, add this:

# Tells Apache to identify which site by name
NameVirtualHost *:80
# Tells Apache to serve the default WAMP Server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost> 
# Tells Apache to serve Client 1's pages to "client1.localhost"
# Duplicate and modify this block to add another client
<VirtualHost 127.0.0.1>
# The name to respond to
ServerName client1.localhost
# Folder where the files live
DocumentRoot "C:/wamp/client1"
# A few helpful settings...
<Directory "C:/wamp/client1">
allow from all
order allow,deny
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost> 

Step 4: Restart Apache and Test

Left-Click your WAMP Server tray icon and select "Restart All Services". Browse to http://client1.localhost and you should see your new site.

Open in new window

0
 

Author Closing Comment

by:badwolfff
Comment Utility
I found the answer myself.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now