How do I redirect a domain to another domain locally?
As Chris already wrote, the problem is that "othersite.dev" is not a number. The format you need is IP hostname1 [hostname2] [hostname3]
.
The deeper problem however is a misunderstanding about the host file and possibly about DNS in general. Basically the host file was not designed for redirections. It was a simple solution back from when CPU cycles where expensive. It lacked features such as the ability to adjust to rapidly changing IP addresses without manually needing to edit a file. These problems were solved by switching from the host file to network based resolver system.
The real answer to your problem therefore is not to use /etc/hosts
, but to use this hierarchical distributed naming system instead. You can do that in several ways. One way is the CNAME as suggested by Chris. Another way would be to give the second server a fixed IP address. Both a real static address, or make a reservation in the DHCP server.
Format of /etc/hosts is "IP" "Hostname" - like 127.0.0.1 localhost
You need a CNAME
in your local DNS server to achieve what you need. You could get the IP of the "othersite.dev" and link it to "testitbeta.dev" like you did with "testitalpha.dev" but when that IP changes you will have to change your /etc/hosts
file as well.