@
@
@deadended2016-06-14 23:33:44
Apache HTTP Server
@deadended, 2016-06-14 23:33:44

How to correctly configure redirection of all requests for any subdomain name to the appropriate folders on the apache2 web server?

Greetings,
I tried different variations of the settings, I came to this look.
Dns set up, added the *.mydomain.ru subdomain.
But subdomains stubbornly do not refer to folders ... I searched for errors in the Apache logs - nothing.
Maybe this is an old version and the second Apache does not understand this code?

<virtualhost *:80>
ServerName www.my_domain.ru *.my_domain.ru
ServerAlias my_domain.ru www.my_domain.ru 
ServerSignature Off
RewriteEngine on
RewriteCond %{HTTP_HOST} ^my_domain\.ru [NC]
RewriteRule ^/(.*) http://www.my_domain.ru/$1 [L,R]

VirtualDocumentRoot /var/%1
ErrorLog /var/log/my_domain.ru/error.log
CustomLog /var/log/my_domain.ru/access.log combined
ServerSignature On
Options FollowSymLinks Includes MultiViews ExecCGI
UseCanonicalName Off
</virtualhost>

The site is in the folder /var/www subdomains in the same place as - /var/sub1

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly, 2016-06-15
@Neolith

Virtual hosts enabled (a2ensite) ?

A
Alexey, 2016-06-15
@alsopub

I just checked and it worked right away.
Apache config:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /www/testdomain

    ServerName www.testdomain.local
    ServerAlias *.testdomain.local
    VirtualDocumentRoot "/www/testdomain/%1"

</VirtualHost>

Mod_vhost_alias module must be connected
Apache version - Apache/2.2.15

D
deadended, 2016-06-15
@deadended

most importantly I don't see any request error in the logs.. tried in different browsers the result is the same so it's not a cache.

C
Cavin March, 2017-03-01
@ForbsmC

How to create dynamic subdomains?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question