Most web servers support name based virtual hosting and can display different content based on the hostname provided by the web browser visiting that server.
You have probably set up more than one name based virtual host and content for localtest.com
will only get displayed when that domain is used.
A different or default name based virtual host, with different content, will get used when the web browser provides a different hostname or the servers IP-address is used.
Your best solution:
Get your own domain i.e. example.com
Set up DNS records such as for example www.client-name.example.com
, dev.client-name.example.com
and www.otherclient-name.example.com
to point to the IP-address of your public web server and/or your development system(s)
Set up name based virtual hosts with those valid host names
Then you don't have to muck about with hosts file entries, can always easily use a conventional URL and you can for example also get valid TLS certificates.
- Bonus If you're (also) using a public web server consider setting up access controls (i.e. grant access from your own IP-address and/or set up basic authentication to require a valid username/password for access) and then your clients can visit their demo sites as well without a need to set up hosts file entries.
As alternative solution alternative is to ensure that localtest.com
becomes the default virtual host. Typically in Apache httpd that happens when you disable the 000-default.conf (and/or all other virtual host entries or) or by making the localtest.com
the first entry that gets loaded by giving the configuration file a name that gets lexicographically ordered first i.e. name the config 0000-localtest.conf
instead of localtest.conf