Subdomain on localhost

I would like to create a registration form that creates subdomains (still on the local host), but I have some problems. I know how to create subdomains by writing, for example, 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 the hosts:

 127.0.0.0 something.localhost 

It works, but I want that when registering a new subdomain (for example: other), when I try to open other.localhost, it opens the specified folder (../www/other/), I tried it in vhosts with "ServerName *. localhost "," ServerName localhost "," ServerAlias ​​* .localhost "," ServerAlias ​​localhost "and on hosts" 127.0.0.1 * .localhost "with all permutations, but none of them worked for me. I thought about this, that when registering, I put a new block in vhosts with optimal data, but I do not think this is a very safe / possible / or best way to do it.

Hope someone can help me!

Thanks in advance!

+4
source share
5 answers

You can try rewriting that converts the subdomain to a folder.

For example, mystuff.localhost becomes localhost / mystuff

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

+2
source

http://*.lvh.me/ is an alias of localhost . Ideal 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 is gone, will change to a working domain

+27
source

lvh.me is also an alias for localhost. Ideal for testing subdomains like Jamo for lvho.st.

+9
source

try adding another domain to serveralias:

 ServerAlias something.localhost other.localhost 
+2
source

You should create a dynamically configured mass shared hosting .

This allows you to define one virtual host entry to handle all incoming requests for different hosts and delegate each request to the appropriate directory.

Thus, you do not need to configure a new virtual host for each new domain you add. Instead, you simply create a directory in the file system and everything works.

First you enable the mod_vhost_alias extension:

 sudo a2enmod vhost_alias 

Then configure your single virtual host entry as follows:

 # get the server name from the Host: header UseCanonicalName Off # this log format can be split per-virtual-host based on the first field # this makes it easy to grep LogFormat "%V %h %l %u %t \"%r\" %s %b" combined <VirtualHost *:80> # the %0 is replaced by the host name on each request # if you want to use only part of the domain as directory # you would have to change the %0 for a %1 or %2 depending # on which part of the domain you want to take. VirtualDocumentRoot /your-main-directory/%0 # configure your main directory anyway you want it <Directory /your-main-directory> Options Indexes FollowSymLinks -MultiViews AllowOverride All Order allow,deny allow from all </Directory> #I have a single cgi-bin directory, but there is also a VirtualScriptAlias # available in case you need it. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 
0
source

All Articles