Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 [email protected]
    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!

like image 461
matthew3r Avatar asked Nov 26 '22 22:11

matthew3r


1 Answers

http://*.lvh.me/ is an alias to localhost. Perfect for testing subdomains.

$ host lvh.me
lvh.me has address 127.0.0.1
$ host foo.lvh.me
foo.lvh.me has address 127.0.0.1

Edit: 2016/07: lvho.st went away, swapped for working domain

like image 139
jpillora Avatar answered Dec 04 '22 03:12

jpillora