This may be better suited for Server Fault, so someone can migrate it if need be.

For the purposes of testing, I want to redirect a domain name I own to my localhost. How do I do this? Can I simply set the redirect to Also, I am using windows. Any help is appreciated.


This answer relates to setting up a local testing environment that works on the LAN only. It seems from comments that the requirement is to redirect all external requests as well - this is a different requirement and is better covered by the other answers. (Although you might still need the points covered in this answer depending on the capability of your router. ie. Does it allow loopback?)

In your Windows HOSTS file you can set a mapping from your domain to your localhost (   example.com

Located in C:\Windows\System32\drivers\etc\hosts

Any requests for example.com will then go to your localhost - this is suitable for testing just on your local machine.

If you want to be able to test this from any machine on your LAN (including phones, tablets, etc.) then you can set an A record in the DNS Zone for that domain (perhaps for a localtest. subdomain) that points to the internal IP address of your server. eg.

  • 1
    Perfect solution if you want it to work only locally.
    – gronostaj
    Mar 1 '13 at 23:59
  • 1
    This was my first thought, too, so I tried adding an entry for microsoft.com. Didn't work. I still got the genuine Microsoft site. Possibly I should have rebooted or done something else to clear my caches. Mar 2 '13 at 0:03
  • @NicoleHamilton: Your machine/browser (some more than others) will cache the resolved DNS, so you might not see the change immediately. You can forcefully clear the DNS cache with ipconfig /flushdns from the command line. ... You also need a web server running on the localhost that is listening for requests to example.com.
    – MrWhite
    Mar 2 '13 at 0:07
  • 1
    Sorry, you must have misunderstood what I meant. I want all traffic that tries to access mydomain.com to be redirected to my local server
    – starscape
    Mar 2 '13 at 0:11
  • @TehEpicPineapple: A local (web)server on your LAN? Yes, the HOSTS file can do this. If the server is not the localhost, then substitute the IP address for whatever is the local IP address of your server. Or are you wanting this to be accessible from outside of your LAN? In which case you'll need to setup A records in the DNS, as in MarkusDBX's answer.
    – MrWhite
    Mar 2 '13 at 0:16

First you need your external IP address, if you want anyone else to reach your domain.

Second you need a DNS server that holds your domain record, and uses an A Host record to point to your external IP.

Then you need to setup your domain to use that DNS server. Probably in the control panel, of the company you used to register the domain.

  • If you only have on public IP address and your internal network is NAT you may also need to setup the port forwarding to your server.
    – Eric G
    Mar 2 '13 at 0:19

The answer will differ depending on whether your local network is on a dedicated IP or not.

If your external IP is dedicated, set an A Record to that IP. You should be able to do this through your domain provider's control panel.

If your external IP is dynamic, like on most home networks, you'll need to use a Dyamic DNS service to always update your domain to point to your local IP, even after it changes. Dyn has been doing this for as long as I can remember, but plenty of organisations offer this service.

After that, it's down to your local network config, which hasn't been mentioned in the question. Presuming you're behind some sort of router, you'll need to tell that direct traffic to your local server's local IP for whatever ports you're using.

  • 1
    It doesn't seem like he wants to redirect everyone to his computer. Rather, he only wants the redirection to happen on his private network.
    – cpast
    Mar 2 '13 at 3:02
  • 1
    He said above, "Sorry, you must have misunderstood what I meant. I want all traffic that tries to access mydomain.com to be redirected to my local server" so I take that to mean external traffic as well... Mar 3 '13 at 15:11

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