httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (Ralf S. Engelschall)
Subject Re: virtual domains using mod_rewrite
Date Wed, 19 Nov 1997 14:47:27 GMT

In article <> you wrote:

> Has anyone done any work on trying to make something like the below work
> completely?  This would be very cool to be able to do fully.  Then you can
> implement a hostname for each user without using virtualhosts.  Hey, you
> can even use only one IP. ==,
> ==, etc.  Only one A record needed
> for all of them.  No mess, no changes required when you add users.

> Problems with the example given include that .htaccess files aren't being
> read properly, logs aren't always as expected, redirects (eg. directory
> requests without a trailing '/') don't give the correct hostname. 

> Some are probably fixable without code changes.  Others may be more
> difficult.

> Anyone else think this is really cool?

Yes, it's a cool idea ;_) But I have to say that I only created the idea as an
example for mod_rewrite but never used it myself... But it's worth to think
about it in depth.. Hmmm...

> Oh, Ralph, I think a lot of mod_rewrite docs from
> would be very useful included in mod_rewrite docs in the distribution.  

Yes, I know. This point is still on my todo-list, but I'm not sure how I
should include it. At least the practical solutions should become a
htdocs/manual/misc/rewrite_solutions.html. No problem from myside according to
copyrights, etc. pp. The only problem is that this page...

> From generated via WML by some nice meta-tags and 1dot-images. This cannot be
used for our Apache distribution tree. So, we have to start over with the
plain HTML markup code (bahhh!) and convert the 1dot-image hacks to plain HTML

>    Virtual User Hosts                                                      
>    Problem Description:                                                
>    Assume that you want to provide for the  
>    homepage of username via just DNS A records to the same machine and  
>    without any virtualhosts on this machine.                             
>    Problem Solution:                                                     
>    For HTTP/1.0 requests there is no solution, but for HTTP/1.1 requests
>    which contain a Host: HTTP header we can use the following ruleset to
>    rewrite internally to            
>    /home/username/anypath:                                             
> RewriteEngine on                                                        
> RewriteCond   %{HTTP_HOST}                 ^www\.[^.]+\.host\.com$      
> RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C] 
> RewriteRule   ^www\.([^.]+)\.host\.com(.*) /home/$1$2                    

With the newer rewriting engine in Apache 1.3 this can be coded more compactly
(in theory, I have not tested it):

    RewriteEngine on                                                        
    RewriteCond   %{HTTP_HOST}  ^www\.([^.]+)\.host\.com$      
    RewriteRule   ^(/.*)        /home/%1$1

And BTW: Because of the restrictions you mentioned, couldn't we try the URL
Look-Ahead feature (%{LA-U:url}) of mod_rewrite to overcome some stuff? What I
mean is this (I hope it still works, because I tried such stuff 1996 the last
time ;_):

    RewriteEngine on                                                        
    RewriteCond   %{HTTP_HOST}  ^www\.([^.]+)\.host\.com$      
    RewriteRule   ^(/.*)        /~%1$1                    [C]
    RewriteRule   .*            %{LA-U:REQUEST_FILENAME}  

This should first rewrite to /~USER/foo/, then
do a URL-based subrequest for this and then lookup the target filename which
is then used as the URL/filename substitution in the main request. Hmm...
but perhaps I'm totally crazy and we are now approaching

                                       Ralf S. Engelschall

View raw message