8

I want to redirect all my browser request to abc.com when a request is sent to xyz.com I was able to do this by adding an entry in the hosts file under windows.

However I see that i can go to http://abc.com when i type in http://xyz.com:8080 but I cannot seem to get the same redirection over https.

I found out that you cannot mention ports in the host file. Need some help on this

frictionlesspulley
  • 11,070
  • 14
  • 66
  • 115

8 Answers8

14

HTTPS is specifically designed so that you can't do this - not only is one of the core points of SSL/TLS that the conversation be encrypted, it also ensures that you really are talking to who you think you are, that you haven't been redirected to a fake site via DNS.

Ana Betts
  • 73,868
  • 16
  • 141
  • 209
  • 1
    ...true, but: that's only related to not being able to get (as in: *buy*) the certificate of `xyz.com` to install that on `abc.com`; it's not a limitation of using the `hosts` file to define specific IP addresses. – Arjan Aug 05 '15 at 19:34
7

That's not what the hosts file is for. It's about the hosts that you are referring to. abc.com and xyz.com are hosts.

All the hosts file does is associate a host name with an IP address. Nothing else is possible.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
2

Get a clone of the part you need from the genuine site.. put it on local iis, add ssl binding using self signed certificate and add entry to hosts file.http://www.selfsignedcertificate.com. if you are in rush with no time to play with iis mgr use appcmd.

Youll get a not verified warning for untrusted issuer.. add it to trusted root cert authorities. http://www.robbagby.com/iis/self-signed-certificates-on-iis-7-the-easy-way-and-the-most-effective-way/

Never tried self signed cert tho.. let us now how your testinggoes.

moral
  • 150
  • 1
  • 6
1

A hosts file is DNS, which is used to resolve a domain name to an IP addresses, which has nothing to do with ports.

If you redirect from https://abc.com to https://xyz.com then they will need to be different servers with different certificates, as an SSL certificate is bound to the domain name.

Which means if you use your hosts file to lookup the ip address of abc.com when you try https://xyz.com then it wont work as the certificate will be for abc.com and wont match the hostheader https://xyz.com sent by your browser.

Chris Diver
  • 19,362
  • 4
  • 47
  • 58
1

If you are using windows command for routing:

netsh interface portproxy add v4tov4 listenport=listen_port listenaddress=any_free_ip_address connectport=localhost_port connectaddress=127.0.0.1

The default port for http request is 80 so if one is using https use 443 as it is the default for https

SHR
  • 7,940
  • 9
  • 38
  • 57
  • More details about this technique can be found [here](https://stackoverflow.com/a/36646749/973425), which makes it possible to not only map IPs but also ports. – Duke79 Sep 22 '19 at 16:18
0

With HTTPS, it'll be to do with the security certificate - likely you can't get around that, or at least ... I hope not.

46bit
  • 1,517
  • 10
  • 9
0

Putting an entry in your hosts file only associates your human readable host name with an ip address, the rest happens in the application that makes http requests.

parts of uri on wikipedia: https://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/URI_syntax_diagram.svg/1068px-URI_syntax_diagram.svg.png

When ever an application makes a request for a resource, let's say your browser, turns what you type for address into a proper uri, which includes scheme.

If you don't type https, or leave the scheme out, you get http. You end up still getting https for some sites, because they use ssl redirection, maybe something like this: https://www.linkedin.com/pulse/how-use-nginx-reverse-proxy-https-wss-self-signed-ramos-da-silva/?articleId=6678584723419226112

moral
  • 150
  • 1
  • 6
-2

Use nslookup xyz.com and get IP

then put this IP to hosts (/etc/hosts in Linux)

the https domain name must transform to IP from

Jeyanthan I
  • 1,611
  • 15
  • 28
test
  • 1
  • 1
  • 1
    I think the redirect can be done only via Apache httpd.conf. Your solution might not be feasible here. If you think it is, please be more descriptive. – Jeyanthan I Apr 04 '16 at 09:39