Edit - After re-reading your question, I do not think this will be possible without a local DNS server to point at as the hosts file only supports FQDN --> IP. However, I think your best bet will be Either some sort of local redirecting proxy server, or an addon that can rewrite host headers.
However, I wrote a guide you may be interested in, which will hopefully explain things a bit better to you...:
This isn't very easy to explain, so if you have any follow up questions, please write in comments and I will be happy to help:
This is not possible BUT putting the IP results in the exact same end result.
Remember, at the end of the day, all that happens when ever you target a FQDN (Fully Qualified Domain Name) is that it translates that address to an IP address.
If you want to forward anyone visiting
domainB.com, you simply put
domainB.com's ip as
domainA.com's entry in the hosts file.
This results in ANYTHING targeting/visiting
domainA.com instead being redirected to
HOWEVER I am guessing you want to redirect a website. Websites are a lot more complicated than this, part of the protocol sends something known as a
Host Header. This is where the web browser contacts the web server AND tells it the address it is trying to access.
For example, visiting Google.com shows the following:
You can also visit Google.com via it's IP address - http://18.104.22.168 - This is because they have a default entry set up which services all requests NOT matching a host header.
So, when you visit
domainA.com it is possible that
domainB.com is only serving
domainB.com content to someone with a host header set to
What you need to do is use a proxy server, Firewall (DPI), or some sort of addon that actually rewrites the Host Header/redirects. Alternatively, if you control the web server domainB.com , you simply need to add
domainA.com to the addresses it will listen to - then any host header with
domainA.com - it will respond with
Adding addition host headers in IIS: