How to create a fake hostname in windows?

3

1

I was reading a book and it said that I can setup a fake hostname in windows by changing the file hosts present in C:/Windows/System32/Drivers/etc/ but it didn't say how to do it.

I mean like http://localhost/ directs me to my wamp home folder www I want to type http://something/ and let the browser directs me to a specific folder.

Does anyone has an idea how to do this ?

ta.abouzeid

Posted 2009-12-11T02:15:45.103

Reputation:

It's not really "fake" host names, its just a mapping of host names to IP addresses. Note also that when you surf in your favorite web browser these names are taken before the DNS resolve is done. – AndersK – 2009-12-11T02:25:42.573

Well, the author referred to it as fake hostnames. After doing some research I found it's called Virtual Host in apache. But still can't grasp the idea. – None – 2009-12-11T02:34:21.547

In WAMP, just add an Apache alias. – Cyclone – 2009-12-11T02:42:12.213

Answers

6

You can't route web address to any folder on windows, http is a web protocol and must have a web server listening on other end. What you can do is to set up virtual host in Apache, preferably a subdomain, and make folder you want to be accessible from the web a DocumentRoot of that host. So:

In host file set

127.0.0.1 myfolder.localhost

and add these lines to httpd.conf, Apache configuration file (or extra/httpd-vhosts.conf, make sure it's being included by main httpd.conf)

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
    DocumentRoot "C:/webroot"
    ServerName localhost
    <Directory "C:/webroot">
        Options Indexes FollowSymLinks MultiViews +Includes
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1>
    DocumentRoot "D:/myfolder"
    ServerName myfolder.localhost
    ErrorLog "D:/myfolder/logs/error.log" # if you want separate logs for this folder
    CustomLog "D:/myfolder/logs/access.log" combined
    <Directory "D:/myfolder">
        Options Indexes FollowSymLinks MultiViews +Includes
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

You must also setup regular webroot for localhost as shown above, otherwise it won't be accessible anymore.

Another (simpler) option to access different folder would be to create in your webroot a hard-like-link to other folder using junction program from Microsoft.

Resistance

Posted 2009-12-11T02:15:45.103

Reputation: 71

5

open the hosts file within C:/Windows/System32/Drivers/etc/ in notepad.

add an entry like this

127.0.0.1       localhost
10.11.100.100   someotherserver

now you can resolve http://someotherserver to 10.11.100.100

Andrew Keith

Posted 2009-12-11T02:15:45.103

Reputation: 356

How to get that ip number 10.11.100.100 for example I want to refer to the folder D:/wamp/www/something/ – None – 2009-12-11T02:26:26.690

1

wait a minute, if your http://localhost is redirecting to a folder, would that mean your running a webserver ?

if thats true , then dont bother editting your hosts file. What your looking for are virtual directories. Configure a virtual directory in your web server.

– Andrew Keith – 2009-12-11T02:29:50.133