using http://server/username instead of http://server/~username

using http://server/username instead of http://server/~username

Post by Ethan Bier » Mon, 15 Feb 1999 04:00:00



I am setting up a server, and I want users to be able to access their
home directories as
        http://server/username
instead of the "standard"
        http://server/~username

What is the easiest way to do this?  I thought I could do it using
UserDir, but it seems that it automatically assumes ~user.  Now I'm
thinking mod_rewrite might be a better choice, but I'm not famailar with
how to do it.

Thanks for any help.

--Ethan

-----------------------------------------

Lehigh University
Computer Engineering Major, Class of 1999
http://www.lehigh.edu/~ecb2

 
 
 

using http://server/username instead of http://server/~username

Post by Joshua Sliv » Mon, 15 Feb 1999 04:00:00



> I am setting up a server, and I want users to be able to access their
> home directories as
>    http://server/username
> instead of the "standard"
>    http://server/~username
> What is the easiest way to do this?  I thought I could do it using
> UserDir, but it seems that it automatically assumes ~user.  Now I'm
> thinking mod_rewrite might be a better choice, but I'm not famailar with
> how to do it.

First, you need to be a little more specific.

Do you need to serve content other than userdirectories?  (In other
words, do you want to serve anything out of the document root?)

If no, just use something like
AliasMatch /(.*)/?(.*) /home/$1/public_html/$2  
or
RewriteRule /(.*)/?(.*) /home/$1/public_html/$2
(completely untested, of course)

If yes, you need some way for the server to differentiate between
requests which should be served out of the document root, and requests
which should be served out of the user directories.  One method is
to enumerate all the user directories, and setup an alias for each, as
in
Alias /ethan /home/ethan/public_html
If you have lots of them, you could use an external map file and have
mod_rewrite look up the appropriate directory.

--
Joshua Slive

http://finance.commerce.ubc.ca/~slive/

 
 
 

using http://server/username instead of http://server/~username

Post by Ethan Bier » Mon, 15 Feb 1999 04:00:00


The alias method you mentioned may be a bit cumbersome, because there
could potentially be several hundred users.  So now I have the following
rules in place:

RewriteRule ^/$ /usr/local/apache/htdocs/index.html [L]
RewriteRule /(.*)/?(.*) /home/$1/$2

Which basically makes the index.html file appear if they go to the root
directory.  Every other request is treated as a home directory (which is
the main purpose of the server).  However, isn't there an RE that I can
set up that would be a little bit more intelligent?  For example, if
there was a . after the first / (but before any second /) in the URL, it
would get directed to the appropriate page in the home directory.  If
there was no period (since user names won't contain periods), it gets
treated as a user's home directory?  For example:

http://server/index.html   is at /usr/local/apache/htdocs/index.html
http://server/graphic.gif is at /usr/local/apache/htdocs/graphic.gif
but
http://server/jsmith           is located at /home/jsmith/index.html
http://server/jdoe/page.html   is located at /home/jdoe/page.html

I'm a little rusty on my RE's, but there should be a way to search for a
period between the / marks.

--Ethan



> > I am setting up a server, and I want users to be able to access their
> > home directories as
> >       http://server/username
> > instead of the "standard"
> >       http://server/~username

> > What is the easiest way to do this?  I thought I could do it using
> > UserDir, but it seems that it automatically assumes ~user.  Now I'm
> > thinking mod_rewrite might be a better choice, but I'm not famailar with
> > how to do it.

> First, you need to be a little more specific.

> Do you need to serve content other than userdirectories?  (In other
> words, do you want to serve anything out of the document root?)

> If no, just use something like
> AliasMatch /(.*)/?(.*) /home/$1/public_html/$2
> or
> RewriteRule /(.*)/?(.*) /home/$1/public_html/$2
> (completely untested, of course)

> If yes, you need some way for the server to differentiate between
> requests which should be served out of the document root, and requests
> which should be served out of the user directories.  One method is
> to enumerate all the user directories, and setup an alias for each, as
> in
> Alias /ethan /home/ethan/public_html
> If you have lots of them, you could use an external map file and have
> mod_rewrite look up the appropriate directory.

> --
> Joshua Slive

> http://finance.commerce.ubc.ca/~slive/

--
-----------------------------------------

Lehigh University
Computer Engineering Major, Class of 1999
http://www.lehigh.edu/~ecb2
 
 
 

using http://server/username instead of http://server/~username

Post by Joshua Sliv » Mon, 15 Feb 1999 04:00:00



> The alias method you mentioned may be a bit cumbersome, because there
> could potentially be several hundred users.  So now I have the following
> rules in place:
> RewriteRule ^/$ /usr/local/apache/htdocs/index.html [L]
> RewriteRule /(.*)/?(.*) /home/$1/$2
> Which basically makes the index.html file appear if they go to the root
> directory.  Every other request is treated as a home directory (which is
> the main purpose of the server).  However, isn't there an RE that I can
> set up that would be a little bit more intelligent?  For example, if
> there was a . after the first / (but before any second /) in the URL, it
> would get directed to the appropriate page in the home directory.  If
> there was no period (since user names won't contain periods), it gets
> treated as a user's home directory?  For example:
> http://server/index.html      is at /usr/local/apache/htdocs/index.html
> http://server/graphic.gif    is at /usr/local/apache/htdocs/graphic.gif
> but
> http://server/jsmith              is located at /home/jsmith/index.html
> http://server/jdoe/page.html      is located at /home/jdoe/page.html
> I'm a little rusty on my RE's, but there should be a way to search for a
> period between the / marks.

Should be relatively simple.  Something like this may work
RewriteRule ^/([^\.]+)[/$](.*) /home/$1/$2

If I'm correct, this should be "Match an initial '/' followed by one
or more characters that are not '.', followed by either '/' or end of
line, followed by zero or more characters."  Requests for the document
root should not match this since they will have a '.' before they
reach either '/' or end of line.  Therefore, you just let them fall
through to normal processing.

If you want to get more complicated, and you don't mind the extra
overhead, you could also use the technique detailed in
http://www.engelschall.com/pw/apache/rewriteguide/#ToC13 to test if
the file exists in the document root, and if not, then go to a user
directory.

--
Joshua Slive

http://finance.commerce.ubc.ca/~slive/

 
 
 

using http://server/username instead of http://server/~username

Post by j a y » Tue, 16 Feb 1999 04:00:00



Quote:}http://server/index.html  is at /usr/local/apache/htdocs/index.html
}http://server/graphic.gif        is at /usr/local/apache/htdocs/graphic.gif
}http://server/jsmith          is located at /home/jsmith/index.html
}http://server/jdoe/page.html  is located at /home/jdoe/page.html

Ethan,  I am going to assume from your .edu that you have some "control"
over who gets what userid on the systems.  If this was an ISP it would be
interesting having to explain why you can't have the following as userid's:
        icon
        images
        about
        home
        support
        includes
        pics
        gifs
        jpegs
        data
        etc... etc... (any common directory name a webmaster might use)

Using this http://server/username approach will have some impact on your
choices of hierarchy organization name spaces in your DocumentRoot. Also,
if you have just started using the .dist configuration files you might want
to examine any naming conflicts. i.e. and lines that provide Alias

I would suggest that you place your DocumentRoot in a place that allows
for a more effective use of your rewrite rules and key off of some value
such as /users/ for example to indicate that you have entered user web
spaces.

ex.

RewriteRule   ^/users/(([a-z0-9])[a-z0-9]+)(.*)  /home/$1$3

This will also allow you some flexibility in hashing your user filespaces
more efficiently.

Just an idea,
Jay

--

http://www.fudge.org            I C Q # 4 6 6 3 6 6 8
CU/iVisit: Fudge                IRC/AIM/TIK: Qthrul
"You cannot uncook Mushoo pork once is has been cooked" -- wiseman