How to "rewrite" subdomains to subdirectories?


#1
  1. I wish to use .htaccess to internally rewrite (NOT external redirect) all subdomain request to corresponding subdirectories. For instance,
    http://xxx.ucdbbs.com/sub_dir/
    will be internally rewritten as
    http://ucdbbs.com/xxx/sub_dir/

I mean internally “rewrite”, not “redirect”, so that the address won’t change in end user’s browser.

Here’s what I tried with .htaccess
########################
RewriteEngine on
RewriteCond %{http_host} !^www.mydomain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.).mydomain.com$ [NC]
RewriteRule ^(.
)$ http://mydomain.com/%1/$1 [R=301,L]
########################

But it did nothing with those rewrite rule above, I don’t know what’s the problem here.

I followed the instruction here:

  1. And then I tried the CPanel subdomain function, and set up one subdomain, “subdomain1”. But when I visit
    http://subdomain1.mydomain.com/Sub_dir1/
    The address in my browser CHANGED, and redirect to
    http://mydomain.com/subdomain1Sub_dir1/
    Note the “/” between “subdomain1/Sub_dir1” got eaten by Dreamhost server.
    And acturally I wish the address rewriting happens internally in the server side, so that the user won’t notice any change of web address via their browser.

Could you please tell me how to make this?

Great thanks.


#2

Someone mentioned similar problem here:
http://www.webmasterworld.com/forum92/3555.htm


#3

We’ve got a “Remap Subdirectories” feature that’ll do this for you:

https://panel.dreamhost.com/index.cgi?tree=domain.mapsubdir


#4

I’ve tried the Remap function, but it can’t remap subdomain to subdirectory.

Thanks for your repky.


#5

Oh, if that’s what you want, just create a subdomain from the Panel for each domain you want and point it at the appropriate directory.