faqts : Computers : Internet : Web Servers : Apache

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 13 people (69%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I direct a user to a different page , based on the username, from one central page that all users access.

Jul 16th, 2002 14:16
Jack Nerad, Richard Kut, http://httpd.apache.org/docs/mod/mod_rewrite.html


You can either write a script to do this, or if using mod_auth and
mod_rewrite, via a RewriteRule.
When a user successfully authenticates, the webserver sets the
environment variable REMOTE_USER.  You can use environment variables in
rewrite rules.  This means that you can redirect to a page based on the
username of the authenticated user.
(in a .htaccess file)
RewriteEngine On
RewriteRule ^access$ http://my.srvr.com/%{REMOTE_USER}/index.html [R]
If a user requests http://my.srvr.com/access that is password
protected with mod_auth, after they successfully authenticate, they will
be redirected to username/index.html on the server.
Note that this does not protect the urls to which you are redirecting,
but only redirects to a directory based on the REMOTE_USER environment
variable.