10

I am using Windows 10 with IIS enabled.
I need to setup local websites on different ports with hostnames which I can access locally by using those hostnames.

For e.g.
Website Name: abcd website
Path to Directory: D:/Projects/Websites/abcd.com
Hostname: abcd.com
Port: 1001

Currently I can access the website with localhost:1001 or 127.0.0.1:1001 But I'm looking forward that my local websites should get resolved with hostnames. So, if I go to http://abcd.com/ it should take me to http://localhost:1001/

With this I wish to setup subdomains to some websites as well. I need help to achieve this.

rustygb
  • 306
  • 1
  • 5
  • 13

1 Answers1

18

If you want to do this locally then modifying the HOSTS file of the server hosting your site to point to the local machine's IP when visiting the abcd.com domain should do it.

Modifying your hosts file allows you to override the DNS for a domain, on that particular machine. This is useful when you want to test your site without the test link, prior to going live with SSL; verify that an alias site works, prior to DNS changes; and for other DNS-related reasons. Modifying your hosts file causes your local machine only to look directly at the IP address specified.

  1. Press the Windows key.
  2. Type Notepad in the search field.
  3. In the search results, right-click Notepad and select Run as administrator.
  4. In Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  5. Add the following entry to the file:

    Local IP Address    www.abcd.com
    

    Click File > Save to save your changes.

Source: http://www.rackspace.com/knowledge_center/article/modify-your-hosts-file

NOTE: If you want to do this from another computer you have admin rights on then you use the same approach. If you want to do this from another computer you do not have admin rights on then you should go about getting a dedicated DNS entry set up for this site

ShaneC
  • 2,237
  • 2
  • 32
  • 53
  • Hi @ShaneC, I have tried this but still when i type in http://www.abcd.com it redirects to the website hosted with that domain on the web. But note that when i ping for the hostname www.abcd.com it shows that "Reply from IP_Address". IP address here shown is the one I entered in hosts file. Also, basically what i want is test.localhost.com should bind with 127.0.0.1:1001 and prod.localhost.com should bind with 127.0.0.1:1002. I have seen this happening in my old company environment where i used to work. They must be having some static IP but i keen to know can we do this on localhost. – rustygb Oct 07 '15 at 19:42
  • Strange, the HOSTS file has priority over resolution by DNS servers (https://support.microsoft.com/en-us/kb/172218). This might be beyond my knowledge I'm afraid, I've never bound port numbers to IP addresses, not with the HOSTS file (see http://stackoverflow.com/questions/8652948/using-port-number-in-windows-host-file), user01's answer on that question regarding Fiddler2 may be an option for you – ShaneC Oct 08 '15 at 07:55