Answer the question
In order to leave comments, you need to log in
How to make automatic subdomains in apache2?
How to configure Apache2 so that subdomains are opened from the corresponding directory
site.ru -> /var/htdocs/site.ru/www
www.site.ru -> /var/htdocs/site.ru/www
sub1.site.ru -> /var /htdocs/site.ru/sub1
subN.site.ru -> /var/htdocs/site.ru/subN
Answer the question
In order to leave comments, you need to log in
Did it like this:
<VirtualHost *:80>
ServerName example.ru
ServerAlias *.example.ru
DocumentRoot "/var/www/example.ru"
# другие настройки #
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.ru [NC]
RewriteRule (.*) http://www.example.ru/$1/ [L,R=301]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.ru
RewriteCond /var/www/example.ru/%1 -d
RewriteRule ^(.*) /%1/$1 [L]
</VirtualHost>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question