2

My webhost automatically forwards all requests to *.mydomain.com to the toplevel domain mydomain.com.

I wanted to map any subdomain to a specific folder on my toplevel domain. i.e. sub.example.com must be mapped to example.com/someFolder (without change in the address bar).

After digging around on the net, I came up with this:

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 - this maps to "example.com/sub/login" properly without the change in the address bar. Any help greatly appreciated!

philly77
  • 519
  • 3
  • 8
  • 14

1 Answers1

3

only small change needed:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.example\.com.*$
RewriteRule (.*) myfolder/$1 [L]

stripped out http:// at the rule which tells Apache to send a Redirect header instead of proper server-side rewrite.

Michal M
  • 9,322
  • 8
  • 47
  • 63
  • Sorry, it was my fault, I was doing a PHP redirect with the absolute (direct) URL within that so it looked as if it was not working! Thanks! – philly77 Oct 19 '09 at 13:40