Testing Subdomains Locally with Ease
When you test subdomains locally using localhost
, it can be a pain since it won’t work out of the box for subdomains you haven’t added to /etc/hosts (since there is no support for wildcard subdomains). You can verify this easily enough:
~ $ ping john.localhost ping: cannot resolve john.localhost: Unknown host
So, when you want something more flexible - there is another easy answer. You can use “lvh.me”, a domain which resolves to 127.0.0.1 (for all subdomains):
~ $ ping lvh.me PING lvh.me (127.0.0.1): 56 data bytes
So, you’re actually set up for this right now:
~ $ ping john.lvh.me PING john.lvh.me (127.0.0.1): 56 data bytes
Pretty awesome! You need an internet connection to use it, so what I do normally is throw the subdomains that I know I’ll use into /etc/hosts - that way they work offline too!