Для реализации этого добавляем в конец конфига апача (httpd.conf) следующее:
RewriteEngine On
## Create a handle to convert upper or mixed-case to lower-case
RewriteMap lowercase int:tolower
##———————————–
## where hostname has www prefix
##———————————–
## Firstly create custom variable that contains the host without the www prefix
RewriteCond %{HTTP_HOST} ^www.(.*)$
RewriteRule .? – [E=noWWWHost:%1]
## Map the virtualhost to the documentroot
RewriteCond %{REQUEST_URI} !^/~
RewriteCond %{HTTP_HOST} ^www.
RewriteRule ^/(.*)$ /home/vhosts/${lowercase:%{ENV:noWWWHost}}/public_html/$1
##———————————–
## where hostname *does not* have www prefix
##———————————–
## Map the virtualhost to the documentroot
RewriteCond %{REQUEST_URI} !^/~
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^/(.*)$ /srv/http/vhosts/${lowercase:%{HTTP_HOST}}/public/$1