Any subdomain point to internal directory with .htaccess

Viewed 22

I was trying to run a few stackoverflow solutions but none of them was working for me

I want any subdomain would show the content of the internal directory.

for example :

test.example.com

would take it's content from :

example.com/subdomains/test

just to clarify i do not want to redirect to the internal directory I still want it to appear as if it's real subdomain so the URL should remain

test.example.com

I tried:

RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ https://example.com/subdomains/%1
1 Answers

Whenever you give and absolute URL with a scheme/host/port different from current, you force a redirect. This should work:

RewriteCond %{IS_SUBREQ} !true
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com
RewriteRule .* subdomains/%1/ [L,QSA]
Related