I\'ve read a lot of questions and answers about this on here but none that seem to solve my specific problem.
I want to redirect any subdomain to the subdirectory to
I named the subdirectories under $_SERVER['DOCUMENT_ROOT']
match with my subdomains like so:
/
var/
www/
html/
.htaccess
subdomain1.domain.com/
subdomain2.domain.com/
subdomain3.domain.com/
Where /var/www/html
stand as 'DOCUMENT_ROOT'
. Then put following code in the .htaccess
file:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/%{HTTP_HOST}/
RewriteRule (.*) /%{HTTP_HOST}/$1 [L]
It works as redirect wildcard subdomains to subdirectories, without changing URL in address bar.
Beside of vhost, you may also put the subdirectories outside root and access it using alias as described here. Then put the same .htaccess
code in that location.