Pointing a subdomain to a subfolder using .htaccess
My web host automatically redirects all requests to * .mydomain.com to the top level domain mydomain.com.
I wanted to map any subdomain to a specific folder in my top level domain. that is, sub.example.com should be mapped to example.com/someFolder ( no change in the address bar).
After digging around the net, I came up with the following:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.example\.com.*$
RewriteRule (.*) http://example.com/myfolder/$1 [L]
This seems to work well, except for one problem: when I go to the URL sub.example.com, the URL in the address bar changes to example.com/myfolder. But, when I do something like sub.example.com/login it correctly matches "example.com/sub/login" without changing the address bar. Any help is greatly appreciated!
+2
source to share
1 answer