I am writing an web application that behaves differently depending on a url prefix. The format is something like:
https://myprefix.mycompany.com
The web app behaves differently based on myprefix. My web app extract that part from the URL and act on that.
However, when I test on my local, I use an localhost address:
https://localhost:1234
I counldn't do something like:
https://myprefix.localhost:1234
What is the best way for me to test this scenario?
Many thanks
I'm not sure about same behaviour at windows. I'm working on linux mint.
You can use
lvh.me:port
as a local domain. You can imagine that your project is deployed onlocalhost:port
on this domain.Instead of
sub.localhost:port
you've to usesub.lvh.me:port
UPD
sub.localhost:port
works at chrome. Firefox automatically adds www. at the beginning of entered domain that can cause problems with subdomains testingUnfortunately, because
localhost
is not a proper domain, you can't add a subdomain to it like that. You can, however, trick your computer into thinking it owns a specific domain and test things that way. For instance, if you have a UNIX-based operating system, open (as root) the file/etc/hosts
and add a line (or lines) like this:Your computer will now treat both
example.com
andsubdomain.example.com
as belonging to itself. If you visit either in your web browser, they will work the same, in principle, aslocalhost
, but your web server will see the correct domain in its Host header.