Apache mod_rewrite is your friend, it can use HTTP headers.
RewriteEngine On
RewriteCond %{REMOTE_USER} ^joecorleone101$
RewriteRule .* dir3/ [R,L]
- If HTTP REMOTE_USER equals joecorleone101 use the rewrite rule
- Match against everything (.*)
- Rewrite url to dir3
- [R] is redirect
- [L] stop rewriting
You can also use the REMOTE_USER in the substition part:
RewriteCond %{REMOTE_USER} ^.*$
RewriteRule .* %{REMOTE_USER}/ [R,L]
- If REMOTE_USER is filled (^.*$) use the rewrite rule
- Match against everything (.*)
- Rewrite url to the value in REMOTE_USER
- [R] is redirect
- [L] stop rewriting
This also works from .htaccess but has some behavior differences, the directory is removed in the pattern matching and added in the substitution part.
To use the value matched in the RewriteCond you can use the %N (1 <= N <= 9).
RewriteCond %{REMOTE_USER} (\d{3})$
RewriteRule .* http://www.example.com/%1 [R,L]
- Match against users who's name end with 3 digits (\d{3})$
- Match against any given url (.*)
- Rewrite it to http://www.example.com/123 (if user ends with 123)
- Redirect and stop rewriting [R,L]