[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-users] translating subdomain name to username



On Sun, 4 Feb 2001, Jim Carey wrote:

> Hi,
> 
> I would like to be able to setup a site where I can translate the hostname
> to a username and then use that area as my doument root.
> 
> ie www.mydomain.com and mydomain.com go to std root
> sales.mydomain.com -> /home/sites/www.mydomain.com/users/sales/web
> info.mydomain.com -> /home/sites/www.mydomain.com/users/info/web
> 
> etc
> 
> any ideas - can someone point me somewhere where I can figure this ourt ?
> (serveralias,rewrites etc)

There is a close example on apache rewriteguide ...

adapting it a bit i'd guess something about like this...

ServerAlias sales.mydomain.com   
#(need one for each username!)

...

#existing...
RewriteCond %{HTTP_HOST}        !^1.2.2.4(:80)?$

#remove next line, it rewrites anything that is not www.mydomain
#RewriteCond %{HTTP_HOST}	!^www.mydomain.com(:80)?$

#existing
RewriteRule   ^/(.*)    http://www.mydomain.com/$1 [L,R]

#the above now only fixes IP -> domain, (before it mapped anything not
#www.mydomain to www.mydomain, we don't want this

#now rewrite host.mydomain.com/* to www.domain.com/users/host/*

#first catch and save (host) from host.mydomain
RewriteCond   %{HTTP_HOST}  ^[^.]+\.mydomain\.com$

#now test if it worked so we dont' map nothing.mydomain oddly (C=chained)
RewriteRule   ^(.+)         %{HTTP_HOST}$1 [C]

#ok, now rebuild the entire thing, necessary along with PT cause of
#following Alias used to handle /user/ mapping (below is 1 line stupid 
pico)

RewriteRule
      ^([^.]+)\.mydomain\.com(.*) http://www.mydomain.com/users/$1$2 [PT]

#keep remaining default Virtual host stuff
RewriteOptions inherit
...

------
caveats: i'm guessing, it's untested , you may have to fiddle a bit...
         it might make a whopping big security hole ;)
         usernames are case sensative, domain names are not...
	 you will have to make dns entries for every username.mydomain...
	 you may find this is somewhet of a pain ;0