Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 :)

share|improve this question
add comment

closed as off-topic by Tom O'Connor Aug 14 '13 at 21:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must be relevant to professional system administration. Server Fault is a site dedicated to professionals; novice questions are off-topic. Please see the Help Center for more information on topicality. The best advice we can give you is to hire a professional to help you out." – Tom O'Connor
If this question can be reworded to fit the rules in the help center, please edit the question.

4 Answers

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.

share|improve this answer
add comment

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>
share|improve this answer
add comment

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 htt*x*...

share|improve this answer
    
They both redirect back to localhost too. :-( –  Josh Mar 6 '10 at 0:21
add comment

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.

share|improve this answer
    
In name resolution there is not fake or valid. And it is working with loopback address. –  Mircea Vutcovici Jun 18 '12 at 2:49
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.