'/etc/hosts' , http links are redirecting, but https links are not redirecting

27,923

Solution 1

/etc/hosts does not care about protocols, it handles host names. Moreover, // is not a comment character in /etc/hosts. See

man hosts

for details.

127.0.0.1 test.com

should be enough for redirecting both http and https. Do you run a service listening for https connections on your localhost?

Solution 2

I thought I was having a similar problem.

For anyone who makes the same silly mistake I did...

I was testing a new webserver by rerouting the requests to a different IP by /etc/hosts.

I did tail -f access_log on my web server and saw all my test requests, except the https ones. I spent a few minutes trying to figure that out.

Finally, I realized that I log SSL requests to a different file. Those log entries were working just fine, in access_ssl_log. Doh!

Share:
27,923

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I edited /etc/hosts file and entered below information :

    127.0.0.1    test.com  //working
    
    127.0.0.1    https://test.com //not working . 
    

    from the above info, http://test.com is redirecting to 127.0.0.1, but https://test.com is not redirecting to 127.0.0.1 . Is there any way I can do that?

    • sensorario
      sensorario almost 11 years
      I've got the same issue. Have you solved?
  • Sudipta Basak
    Sudipta Basak almost 12 years
    leave those commnents, i just entered them here . My use case is,in my website some parts of the code can be tested only with the domain name, and my website uses https . So, if it is just http, i can test locally with the domain name . But as it is https, I am unable to test locally .
  • Sudipta Basak
    Sudipta Basak almost 12 years
    Once more: Is your local webserver configured to handle https requests?