регулярные-выражения – How to automatically create subdomains?

Question:

How to set up Apache2 for subdomains?

For instance:
If the query www.example.com or example.com was entered in the browser, the server returned the contents of the /var/www/example.com/www directory. If subdomain1.example.com is requested, then the server should return /var/www/example.com/subdomain1 . Accordingly, for subdomain2.example.com/var/www/example.com/subdomain2 , etc.
If the subdomainN directory does not exist, return a 404 error

Answer:

redirect in .htaccess will help

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$  /var/www/example.com/subdomains/$1 [L]

I think you wanted it

Scroll to Top