Answer the question
In order to leave comments, you need to log in
Automatic subdomains in Apache?
I will say right away that this is not a repetition, because in similar questions I did not find the correct answer.
I have a folder /var/www/mysite.net.ua/www/ . It contains the files of the main site, which opens at mysite.net.ua
In the /var/www/mysite.net.ua folder there are folders /vasya , /kolya , /petya , i.e.:
/var/www/mysite .net.ua/vasya
/var/www/mysite.net.ua/kolya
/var/www/mysite.net.ua/petya
And there can be many such folders. It is necessary to make them open at their addresses respectively:
vasya.mysite.net.ua
kolya.mysite.net.ua
petya.mysite.net.ua
I found this solution: in the /etc/apache2/sites-available/mysite.net.ua.conf
file , I write to the VirtualHost section :
Define root_domain mysite.net.ua
Define root_path /var/www/mysite.net.ua
DocumentRoot ${root_path}
ServerName ${root_domain}
ServerAlias *.mysite.net.ua
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.net.ua$
RewriteCond %{HTTP_HOST} ^((.*)\.)mysite.net.ua$
RewriteRule ^/(.*) /%2/$1
Answer the question
In order to leave comments, you need to log in
<VirtualHost *:80>
ServerName mysite.net.ua
ServerAlias www.mysite.net.ua
DocumentRoot /var/www/mysite.net.ua/www
</VirtualHost>
<VirtualHost *:80>
ServerName mysite.net.ua
ServerAlias *.mysite.net.ua
UseCanonicalName Off
VirtualDocumentRoot /var/www/mysite.net.ua/%-4
</VirtualHost>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question