📜 ⬆️ ⬇️

Custom virtual domains

If you look at the URL of the habrahabr.ru user profile, you can see that the third level domain is his login.
This approach is called “user virtual domains”.


Why about theoretical? Because in practice I did not manage to fully launch this technology: when I call vasya.site.ru/index.php, the browser offers to keep index.php, instead of executing it.
There have been attempts to explicitly specify in .htaccess:
  1. AddType application / x-httpd-php .php .htm .html
  2. AddHandler x-httpd-php .php .htm .html
  3. Options Indexes FollowSymLinks
  4. DirectoryIndex index.html index.php

- but still to no avail.

In general, theoretically, it looks like this:
  1. Adding an entry to the settings of the dns server of the form:
    IP_ADDRESS * .site.ru
  2. Add ServerAlias ​​to httpd.conf for a domain:
    1. <VirtualHost site.ru:80>
    2. DocumentRoot / var /www/site.ru
    3. ServerName site.ru
    4. ServerAlias ​​* .site.ru
    5. </ Virtualhost>
  3. Add to .htaccess:
    1. RewriteEngine On
    2. RewriteCond% {HTTP_HOST}! ^ Www.site.ru $
    3. RewriteCond% {HTTP_HOST} ^ ((. *) \.) Site.ru $
    4. RewriteRule ^ / (. *) /% 2 / $ 1
  4. Or parse $ _SERVER ['HTTP_HOST']

')
PS: Strange, but there is not enough information on the network on the subject, is it really out of this approach that such a secret is made .
PSR: Fasting is an issue with a tendency to an article.

UPD 1 :
Related Links:
  1. Bulk SubDomains - bulk add subdomains
  2. nginx: Automatic subdomains and habrahabr
  3. Apache: Automatic Subdomains
  4. Car subdomains in the ranks or wildcards in action
  5. Windows XP, wildcard DNS and localhost subdomains

Source: https://habr.com/ru/post/40212/


All Articles