Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias hostname for localhost

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/?

like image 861
WhatIsName Avatar asked Oct 17 '13 11:10

WhatIsName


People also ask

What is the hostname for localhost?

On almost all networking systems, localhost uses the IP address 127.0. 0.1. That is the most commonly used IPv4 “loopback address” and it is reserved for that purpose.

What is an alias hostname?

A hostname alias is a way of defining alternative names for an existing website URL. You must set up and register the DNS and domain names to use these extra hostnames in aliases.

How do I change my localhost hostname?

Double-click the "Hosts" file in the System 32\drivers\etc folder, then select "Notepad" from the "Open with" list. The file will open in Notepad. Scroll down to the bottom of the file until you see: "127.0. 0.1 localhost." Replace the word "localhost" with the name you prefer.

Can you put an alias in a host file?

For adding a alias name to a server in the hosts file you have to make the following structure: In the first column you have to add the IP-Address, in the second column the host-name and in the third column you have to add the desired alias-name. Any subsequent columns are alias for that host.


2 Answers

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.

like image 87
Oswald Avatar answered Oct 11 '22 22:10

Oswald


the second option (just alias the hostname without the port information) is possible by adding localwebapp to your hostsfile ( /etc/hosts in *NIX, c:\windows\system32\drivers\etc\hosts in windows)

adding

127.0.0.1 localwebapp 

should do the trick (assuming your local python script does not do virtual hosting and serves the same content for all domains requested)

like image 39
Gryphius Avatar answered Oct 11 '22 21:10

Gryphius