localhost redirects to my IP
Posted by: haakym (195.171.123.---)
Date: June 14, 2016 03:29PM

I had to recently wipe my PC and I'm setting up my development environment again using WAMP.

After installing WAMP, if I visit [localhost] instead of seeing the WAMP homepage I get redirected to [x.x.x.x], where x.x.x.x is my IP.

I had this issue on another PC and after setting the inbound rules for Apache HTTP Server in my Windows Firewall settings to allow all domains it fixed the issue. I applied this to my PC, and the issue does not seem to be present for Internet Explorer, whereas for Chrome and Firefox the localhost to my IP redirect issue persists even after clearing the cache for each browser.

My C:\Windows\System32\drivers\etc\hosts file looks like this:

127.0.0.1 localhost
::1 localhost

and my firewall rules look like this:

[i.stack.imgur.com]

I am not currently using vhosts and I'm on a network at my workplace (if that has any implications?)

I also encountered the same issue when using Laragon (see [laragon.org]) which uses vhosts and whenever I visited a virtual host, e.g. mysite.dev it didn't work properly either.

My question on the Laragon forum: [forum.laragon.org]
My question on SO: [stackoverflow.com]

Edit:

1 - Windows 7 64 bit
2 - WampServer 2.5 64 bit
3 - Apache Version 2.4.9
4 - PHP Version 5.5.12
5 - MySQL Version 5.6.17
6 - What color is the WampServer icon: Green



Edited 1 time(s). Last edit at 06/15/2016 01:00PM by haakym.

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: Otomatic (Moderator)
Date: June 14, 2016 04:11PM

Hi,

> I get redirected to [x.x.x.x], where x.x.x.x is my IP.
LAN ip or WAN ip ?
Perhaps a port forwarding problem in your router.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: haakym (195.171.123.---)
Date: June 15, 2016 12:15PM

Thanks for your reply Otomatic.

It's the IP for the LAN I am on at my workplace. If it's a port-forwarding issue is this something the guys responsible for the networking would have to resolve?

Some further info:

If I run ipconfig in the cmd I get

IPv4 Address. . . . . . . . . . . : 172.17.10.213

and when I go to [localhost] in my web browser (even if wamp isn't running) it will redirect to this IP 172.17.10.213.

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: Otomatic (Moderator)
Date: June 15, 2016 12:46PM

Hi,

I think in enterprise network there may be some limitations on the installation of a local server. You should contact the network administrator or IT manager.

What is the content of c:\windows\system32\drivers\etc\hosts file?

Are you running a Windows session as an administrator?

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: haakym (195.171.123.---)
Date: June 15, 2016 12:56PM

Right. I have spoken with the guys who manage the network, but they're a bit clueless as to why it's happening. If I had something more to go on it may help.

Please note that I've got wamp working on another PC on the same network without the redirect issue and prior to wiping the PC I encountering the issue on I had wamp set up just fine also.

As mentioned in my intial post, the contents of c:\windows\system32\drivers\etc\hosts file is as follows:

127.0.0.1 localhost
::1 localhost

I'll also reiterate that the issue is only present in Chrome and Firefox, it doesn't do the redirect nonsense in IE.

Yes my windows session is as an administrator though there's some privileges I don't have.

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: Otomatic (Moderator)
Date: June 15, 2016 02:28PM

Hi,

As it works right with IE, try to clear the cache of Firefox and Chrome.

Try also with 'http://127.0.0.1/' in the address bar.

The content of the hosts file is correct.
This is what concerns me because when you type a URL in a browser, just after the DNS cache, the hosts file is consulted to perform the url relationship to IP.

May be, clear the DNS cache with commande line (as an administrator) : ipconfig /flushdns

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons



Edited 1 time(s). Last edit at 06/15/2016 02:57PM by Otomatic.

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: haakym (195.171.123.---)
Date: June 15, 2016 02:58PM

As I mentioned in the initial post: "... the issue does not seem to be present for Internet Explorer, whereas for Chrome and Firefox the localhost to my IP redirect issue persists even after clearing the cache for each browser."

Same issue with [127.0.0.1]

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: haakym (195.171.123.---)
Date: June 15, 2016 03:26PM

Thanks so much for all your responses Otomatic.

Tried "ipconfig /flushdns", but didn't make a difference sadly.

If my host file is like this:

127.0.0.1 localhost

and I do "ping localhost" I get a response from 127.0.0.1

And if my host file is like this:

127.0.0.1 localhost
::1 localhost

and I do "ping localhost" I get a response from ::1

As it seems to be responding properly in IE and when pinging from the command line, are there some chrome or Firefox specific settings I should be looking at?

When visiting the following URL in chrome: "chrome://net-internals/#dns", I can see the following:

Async DNS Configuration

Internal DNS client enabled: false

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: Otomatic (Moderator)
Date: June 15, 2016 04:01PM

Hi,

Try to add
172.17.10.213 localhost
just under 127.0.0.1 localhost in hosts file. (1)

As you install Wampserver 2.5 (Two years old) you don't have the tool to restart DNS after this modification (This tool is part of Wampserver 3.0.4) you need to open a command windows (as an administrator) and type :

net stop wampapache
ipconfig /flushdns
net stop Dnscache
net start Dnscache
net start wampapache

(1) I try this on my PC with LAN IP 192.168.0.10 and when I type 'http://192.168.0.10/' it opens the homepage of Wampserver.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons



Edited 1 time(s). Last edit at 06/15/2016 04:29PM by Otomatic.

Options: ReplyQuote
Re: localhost redirects to my IP
Posted by: haakym (195.171.123.---)
Date: June 16, 2016 03:04PM

@otomatic

Thanks for all your replies, I think your suggestions got it working for me for localhost, but I was still having the issue with vhosts.

It turns out the network I'm on at my workplace uses a proxy for browsing the web and this was interfering with the dns resolution which is why it was only an issue in the web browser and not the command prompt.

The solution was in the end very simple, I just had to add exceptions to the web browser settings when not to use the proxy for example localhost,127.0.0.1,*.dev.

I've put more details in my SO question, which I have in turn now answered myself: [stackoverflow.com]

Thanks again so much for your help I learnt quite a bit about dns resolution in windows and some commands in the process!

Options: ReplyQuote


Sorry, only registered users may post in this forum.