Alex Emilov
Alex Emilov

Reputation: 1271

Help with htaccess redirect for subdomain

I'm using this code to redirect all subdomains to the subdomain folder. For example test.site.com => site.com/test.

RewriteCond %{HTTP_HOST} !^www\.site\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.site\.com [NC]
RewriteRule ^(.*)$ http://site.com/%1 [L]

When I visit test.site.com it automatically redirects to the folder test/.I want to stay at the domain test.site.com and show the contents of test/ folder without redirecting to the actuall folder.Thanks.

Upvotes: 1

Views: 423

Answers (1)

Mathieu Rodic
Mathieu Rodic

Reputation: 6762

You could do achive that with this code:

RewriteCond %{HTTP_HOST} !^www\.site\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.site\.com [NC]
RewriteRule ^(.*)$ /%1/$1 [L]

Upvotes: 3

Related Questions