I use Symfony2. I have an eample site.com
. How can I do dynamical virual subdomain with username. When users logged in url showed username.site.com
. But username.site.com
equal to site.com
. How can I do?
It's difficult to understand what you exactly want to do. But if I understand right, this may help you: http://www.devops.zone/webserver/dynamic-subdomains-with-mod_vhost_alias/
EDIT: I'm including the text and code from the above link:
For those using a development server for quite a lot of domains or those using some kind of mass hosting, not wanting to reconfigure each and single domain, this module might be interesting: mod_vhost_alias
First of all we need to activate the module which is by default included in the apache2 installation:
a2enmod vhost_alias
or by doing:
cd /etc/apache2/mods-enabled
ln -s ../mods-available/vhost_alias.load vhost_alias.load
Then we need to create a corresponding vhost configuration:
NameVirtualHost *.example.net
<VirtualHost *.example.net>
ServerAdmin admin@example.net
UseCanonicalName Off
VirtualDocumentRoot /var/www/vhosts/example.net/subdomains/%1
DocumentRoot /var/www/vhosts/example.net/subdomains/
<Directory />
# directory options
</Directory>
<Directory /var/www/vhosts/example.net/subdomains/>
# directory options
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
Supposing that the server's name is example.net, apache will now lookup all subdomains of this domain in /var/www/vhosts/example.net/subdomains/
Example: test.example.net will be mapped to: /var/www/vhosts/example.net/subdomains/test
Of course this is not only working with subdomains, this is just an example.