Can't map certain port and path with hosts file

2

2

On my localhost I'm trying to map http://127.0.0.1:8888/site/ to www.test.dev. Hosts file is below.

When I load http://127.0.0.1:8888/site/ I see what I want but for www.test.dev I just see Firefox's Server not found page.

What's wrong with my hosts file?

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost
127.0.0.1:8888/site       www.test.dev

user39822

Posted 2011-10-10T07:55:50.883

Reputation: 169

Answers

4

The hosts file maps names to IP addresses. You cannot put ports or paths in there.

Zoredache

Posted 2011-10-10T07:55:50.883

Reputation: 18 453

So is it possible at all to map http://127.0.0.1:8888/site/ to www.test.dev ?

– user39822 – 2011-10-10T08:04:29.017

From my reading of the question, xe already has a content HTTP server there. Xe wants to pretend that that has a real domain name, presumably for testing out a WWW site privately before uploading the pages to the main public content server. – JdeBP – 2011-10-10T09:57:38.440

3

In your local hosts file, replace your

127.0.0.1:8888/site       www.test.dev

with

127.0.0.1       www.test.dev

then you can visit http://www.test.dev:8888/site

If you want http://www.test.dev/ to retrieve the same site, you can configure your webserver to also listen on port 80 (as well as 8888) and configure virtual hosting in which case the webserver can use the HTTP headers passed by the client (Host: www.test.dev) to identify the required site.

How you do this depends on the webserver you use. For Apache see the documentation for Listen and Virtual Hosts


To make testing easier - use relative URLs throughout the site content. It shouldn't normally be necessary to do what you are asking.

RedGrittyBrick

Posted 2011-10-10T07:55:50.883

Reputation: 70 632