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 the
You should create a dinamically configured mass virtual hosting.
This allows you to define a single virtual host entry to handle all incoming requests for different hosts and delegate each request to the corresponding directory.
This way you avoid having to configure an new virtual host for each new domain you add. Instead you just create the directory in the file system and everything just works.
First you enable the mod_vhost_alias extension:
sudo a2enmod vhost_alias
Then configure your single virtual host entry like this:
# 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>
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
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
try adding another domain in serveralias:
ServerAlias something.localhost other.localhost
lvh.me is also an alias to localhost. Perfect for testing subdomains as Jamo say for lvho.st.