简体   繁体   中英

wamp vhosts issue with multiple hosts

I have 2 codeigniter projects in my wamp localhost and I am trying to set up multiple vhosts.

My directory structure is like this:

- www
    - project
    - projectold

I set up 2 vhosts: project.lh and projectold.lh

here are my httpd-vhosts.conf entries:

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName project.lh
    DocumentRoot "c:/wamp64/www/project"
    SetEnv CI_ENV development
    <Directory  "c:/wamp64/www/project/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName projectold.lh
    DocumentRoot "c:/wamp64/www/projectold"
    SetEnv CI_ENV development
    <Directory  "c:/wamp64/www/projectold/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

I've also uncommented this line in my httpd.conf file:

LoadModule vhost_alias_module modules/mod_vhost_alias.so

EDIT:

This is what's currently in my hosts file:

127.0.0.1 localhost
::1 localhost

127.0.0.1   project.lh
::1 project.lh

127.0.0.1   project.lh
::1 project.lh

127.0.0.1   projectold.lh
::1 projectold.lh

(not sure why there are 2 entries for project.lh)

EDIT 2: This is the .htaccess file in the project.lh directory. There are no .htaccess files for projectold.lh.

RewriteEngine on
RewriteBase /
## Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
##RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The problem I'm having is that when I navigate to projectold.lh, it is somehow pulling in the markup for project.lh. I don't understand why or how this could be happening. I'm thinking there's something I must be missing.

I tried commenting out the project.lh entry in my vhosts file and that didn't fix it. Hoping someone has seen this before.

I'm using Wamp3.1.3.

Creating multiple virtual hosts/websites in Wampserver By Virendra Chandak

To create multiple websites, it would be helpful to have each website setup on the local computer. With Wampserver (or just Apache) we can easily configure multiple websites. Following are the steps to create multiple websites using Apache's configuration. This uses Apache's “Named Virtual Hosts” configuration. I have tested these steps on Wampserver 2.1 running on Windows XP and Windows 7.

Step 1: Set your hostnames or setup Windows to recognize your local websites

After installing WAMP server you can go to the browser and type http://localhost and it opens up a page. Windows by default recognizes the site localhost as referring to itself. We need to setup windows to recognize our other local websites. To do this we need to edit the hosts file. This file is found under the following directory. (Another way to reach this directory is, open the run command or press Windows Key + R, and then type “drivers” and press “OK” then go to “etc”.) C:/Windows/System32/drivers/etc

After going to this directory open the file named hosts in this directory using your favorite texteditor (like Notepad, Editplus, Notepad++).

Note: You may not be able to edit or save this file in Windows Vista or Windows 7. You need administrator rights to edit this file.

Now, you would see a line at the end of the file follows:

127.0.0.1   localhost

This code tells your computer to connect to your own computer when we try to go to

`http://localhost`

Now we should add our site to this file. Lets say our site name is site1. So we would add an entry for it in the hosts file. The updated file would look similar to the following:

127.0.0.1   localhost
127.0.0.1   site1

Save this file and try going to http://site1 This would take you to the same page as http://localhost Now our computer knows what http://site1 is.

Note: Make sure you do not add host entries for external sites like google.com or bing.com. If you add these entries, then the computer would no longer be able to go to the actual websites. Step 2: Create a folder for the website

Wampserver has only one folder or site root to host the website. This folder is typically C:/wamp/www. We should create a different folder for each website. We can create the folder in any directory or drive. (If we create the folder outside of C:/wamp/www we would need some additional settings in Apache described later).

Add some test file in this folder like “index.html” in say C:/wamp/www/site1 directory. Step 3: Setup Apache to serve multiple sites

We would change the file httpd.conf and httpd-vhosts.conf for the Apache setting. Open the file httpd.conf by clicking the WAMP server icon and selecting “Apache -> httpd.conf”. This file is typically located at C:/wamp/bin/apache/Apache2.2.17/conf.

Don't add code to this file, its not a clean and easy way. We just want to un-comment one line in this file that include the vhosts file.

Include conf/extra/httpd-vhosts.conf

Remove the # sign from the front of the line, the changed line should look as follows: Include conf/extra/httpd-vhosts.conf

Now, we will open the file “httpd-vhosts.conf”, which would be typically located inside the extra directory (C:/wamp/bin/apache/Apache2.2.17/conf/extra)

In this file we will add virtual host using the following code:

<VirtualHost *:80>
    ServerAdmin admin@localhost
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    ServerAlias www.localhost.com
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
</VirtualHost>

In the above code the ServerName and DocumentRoot are mandatory, other options are optional.

So if we want to have 3 sites on our local machine as follows

localhost -> C:/wamp/www
site1 -> C:/wamp/www/site1
site2 -> C:/site2

<VirtualHost *:80>
    ServerAdmin admin@localhost
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    ServerAlias www.localhost.com
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/site1"
    ServerName site1
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/site2"
    ServerName site2
    <Directory "C:/site2">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

I have not used all the options for site1 and site2, but it is a good practice to have them. Also notice that the code for site2 has some extra code for Directory. This is necessary to give the server access to that directory. If we don't add this, the server will not be able to access the files in this directory and hence the site would not work. We don't need this for site1 as its inside C:\\wamp\\www directory for which the directory setting are set by defult in wampserver.

Now restart Apache and all your sites should be working. Make sure you add site2 to your hosts file and create the directory for it at C:/site2.

Note: I do not take responsibility for proper functioning of the above mentioned steps under all circumstances. If you download any files, programs from my blog then make sure you protect yourself. I am not responsible for any damages to your computer, website, blog, application or any thing else. I am not affiliated with or do not endorse any of the above mentioned sites.

Original article: https://www.virendrachandak.com/techtalk/creating-multiple-virtual-websites-in-wampserver/

Helped me in the past.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM