Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Assuming that a local Python-Script is running a webserver.

Is there any way to set an alias, so that http://localwebapp/ equals http://localhost:1234/?

Edit: Or at least http://localwebapp:1234/ equals http://localhost:1234/?

question from:https://stackoverflow.com/questions/19425086/alias-hostname-for-localhost

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
170 views
Welcome To Ask or Share your Answers For Others

1 Answer

When the browser sees http://localwebapp/ it first tries to determine the IP address of localwebapp. If this succeeds, the browser establishes a TCP connection with that host, using a specific port (which is 80 for HTTP, unless some other port is mentioned in the URL).

Resolving localwebapp to an IP address does not take port information into account, so pointing http://localwebapp/ to http://localhost:1234/ can only be done by means of a HTTP redirection.

To make http://localwebapp:1234/ the same as http://localhost:1234/, edit the hosts file of your operating system by adding the line

127.0.0.1 localwebapp

The location of the hosts file depends on the operating system. For UNIX-like operating systems, its usually /etc/hosts.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...