----- Original Message -----
From: Chris Blessing <[EMAIL PROTECTED]>

>Anyways, I was wondering if there is a way in Apache (1.3.4) to setup
>users so they can access their webpages via the url: user.foo.com.  I
>can make the cname in the DNS tables and such, but I want to be able to
>access user.foo.com instead of www.foo.com/~user/ or any other
>directory.  I am familiar with virual hosts, but I have only one IP
>address available to me so if anyone can shed some light on this I'd
>really appreciate it.  Thanks...

Contrary to most of the other replies (barring the mod_rewrite gentleman),
it seems apparent to me that you would like automatic translation between
<username>.foo.com and www.foo.com/~<username>/ as opposed to several
hundred (thousand?) VirtualHost directives.

I am currently serving about 900 vhosts on 7 different domains (see
http://www.overthelimit.com) with 10 lines of VirtualHost directive.

The trick is definitely to use mod_rewrite (the rewrite module) for apache.
Assuming you are able to track down the documentation and such explaining
how to compile mod_rewrite into your apache installation (make sure you do
this), here is how you'd do it (having never done anything this complex with
apache, or even realizing that it could do this sort of thing up until a few
weeks ago, being unable to find people familiar with mod_rewrite was very
discouraging.. so here you go):

(This assumes users' html is in /home/username/public_html and that every
username.foo.com resolves to 10.1.2.3)

Note: ensure that this is the first virtualhost entry in your httpd.conf

NameVirtualHost 10.1.2.3

<VirtualHost  10.1.2.3>
    ServerName  redirection-service  # insignificant

    # Enable the rewrite module
    RewriteEngine  on

    # Create a sort of function, "lowercase", that will lowercase things
    RewriteMap  lowercase  int:tolower

    # Only do the rewrite rule below, if the hostname the user is going to,
    # matches the regular expression (<letters, numbers, and
hyphens>.foo.com)
    RewriteCond  ${lowercase:%{HTTP_HOST}}  ^[a-z0-9\-]+\.foo\.com$

    # the Rewrite engine is originally only passed the directory the user
    # is trying to access. we use [C] to Concatenate the hostname they are
    # requesting onto that.
    # we started out with / or maybe /index.html and now have
    # <whatever user they requested>.foo.com/<whatever dir they requested>
    # Notice that anything in () can be referenced respectively by $N
    RewriteRule  ^(.+)  ${lowercase:%{HTTP_HOST}}$1  [C]

    # assuming that we have something.foo.com/something, do the big thing
    RewriteRule  ^([a-z0-9\-]+)\.foo\.com/(.*)  /home/$1/public_html/$2
    # the first thing in () is $1, the second is $2. $1 is the
<thing>.foo.com
    # and $2 is the directory/filename they are requesting.
</VirtualHost>

[insert the virtualhost tags from all of your regular domains, or vhosts
that aren't in /home/username]

So, finally, you should end up with:

<VirtualHost  10.1.2.3>
    ServerName  redirection-service
     RewriteEngine  on
    RewriteMap  lowercase  int:tolower
    RewriteCond  ${lowercase:%{HTTP_HOST}}  ^[a-z0-9\-]+\.foo\.com$
    RewriteRule  ^(.+)  ${lowercase:%{HTTP_HOST}}$1  [C]
    RewriteRule  ^([a-z0-9\-]+)\.foo\.com/(.*)  /home/$1/public_html/$2
    ErrorLog /var/log/apache/redirect-error_log
    TransferLog /var/log/apache/redirect-access_log
</VirtualHost>

The best document I could possibly recommend is:
http://www.apache.org/docs/vhosts/mass.html

Let me know how it comes out, and good luck!

Regards,
Jason Sloderbeck

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to