matthew3r matthew3r - 1 month ago 16
Apache Configuration Question

Subdomain on localhost

I would like to create a registration form which creates subdomains (yet on localhost), but I have got some problem. I know how to create subdomains, writing for example these in vhosts:

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.hleclerc-PC.ingenidev
DocumentRoot "C:/wamp/www/something/"
ServerName localhost
ServerAlias something.localhost
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>


And put this line in hosts:

127.0.0.0 something.localhost


It's working, but what I want is that when I register a new subdomain (for example: other), then when I try to open other.localhost, then it opens the specified folder (../www/other/).
I tried it in vhosts with "ServerName *.localhost", "ServerName localhost", "ServerAlias *.localhost", "ServerAlias localhost", and in hosts "127.0.0.1 *.localhost" with all of the permutation of these, but neither of these worked for me.
I have thinked about it, that on registration I put a new block in vhosts, with the optimal data, but I don't think it's very safe/feasible/or the best way to do.

Hope someone can help me!

Thanks in advance!

Answer

You could try a rewriterule, which converts a subdomain into a folder.

For example, mystuff.localhost becomes localhost/mystuff

otherthing.localhost/some/dir/here becomes localhost/otherthing/some/dir/here