I'm setting up a server (Ubuntu Server 18.04) running Apache2 for my own personal testing and development needs. I can only access it via its local IP (ex.
http://10.0.0.125) or its name on the local network (ex.
http://jeeves), but that's fine for now.
I wanted to create several subdomains on this server to keep unrelated sites properly isolated, but I don't believe I can use actual subdomains:
http://sub.10.0.0.125 doesn't work since an IP isn't a domain, hence can't have a subdomain, and
http://sub.jeeves doesn't work since the browser interprets
.jeeves as a TLD and not as the server's name.
So I came up with another solution:
<VirtualHost *:80> ServerName localhost DocumentRoot /var/www/html AliasMatch "^/~(.*)" "/var/www/$1" </VirtualHost>
Now I can create a directory
/var/www/sub and access it via
A very good compromise, I thought ... except, since it's not a subdomain, and doesn't work like one, a link like
<a href="/foo/"> will refer to
http://jeeves/foo/ and not as desired to
http://jeeves/~sub/foo/. I could deal with that in each site's code, but that would be far from ideal.
My question: Is there any way to make Apache treat the
/~sub/ part of the URL like a subdomain for all intents and purposes (links in particular)? Some kind of BaseDir directive, maybe? I couldn't find one, but that doesn't mean something like it doesn't exist.
Before you suggest it: Getting an actual domain for this server is a bit beyond the scope of my current needs; running a dedicated DNS server seems like too much added complexity; and changing the hosts file on each system isn't exactly scaleable (also not trivial on an iPhone, say).
I feel like my solution would be ideal for my needs, if only it can work.