4

I'm currently using Windows 7 with WAMP to try and work on some software, but my web browsers will not accept cookies from the "localhost" domain. I tried creating a few bogus domains in my hosts file by pointing them to 127.0.0.1 but when I type them in I am automatically redirected back to localhost. I have also configured virtualhosts in apache to correspond with the domains I added to the hosts file and it still redirects back to localhost. Is there anything special I must do on Windows 7 to get around this localhost redirect?

Thanks for looking :)

I'll include my host file here:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1       localhost
# ::1             localhost
127.0.0.1        magento.localhost.com www.localhost.com

Thanks for looking :)

4 Answers 4

3

Here's a similar example from C:\xampp\apache\conf\extra\httpd-vhosts.conf on my own PC.

Please note that this requires a static IP address on your computer; do not use DHCP on the PC which you are using for development. And as Alberto says, you will need corresponding entries in your hosts file (in c:\windows\system32\drivers\etc).

<VirtualHost *:80>
    ServerName localhost
    ServerAlias localhost.config.local
    DocumentRoot "C:/xampp/htdocs"
 <Directory "C:/xampp/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
 </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName 127.0.0.1
    ServerAlias 192.168.1.12
    DocumentRoot "D:/www"
 <Directory "D:/www">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
 </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName mypc
    ServerAlias mypc.config.local
    DocumentRoot "D:/Web-Sites/www"
 <Directory "D:/Web-Sites/www">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
 </Directory>
</VirtualHost>
2

I have several domains setup in that way and works fine, they key is match the ServerName with the alias used in hosts (note that you don't have to use .com or .net in the name):

In httpd.conf:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerName test
    DocumentRoot "D:/web/test"
    ErrorLog C:\Temp\Logs\Apache\test-error.log  ; optional, but useful for development
    CustomLog C:\Temp\Logs\Apache\test-access.log common  ; optional, but useful for development
</VirtualHost>

In hosts

127.0.0.1    test

This should enable requests to http://test/ without redirection.

0

Why not browse to the website using your local IP (httx://192.168.x.x) instead of httx://127.0.0.1 or httx://localhost?

sorry about the httx...

1
  • They both redirect back to localhost too. :-(
    – Josh
    Mar 6, 2010 at 0:21
-1

If you use 127.0.0.1 in your /etc/hosts for your fake domains, they will always go to localhost.

You should use the IP address of your network card, or add a secondary IP address to your network card and use it for your tests.

1
  • In name resolution there is not fake or valid. And it is working with loopback address. Jun 18, 2012 at 2:49

Not the answer you're looking for? Browse other questions tagged .