I am trying to write an htaccess file performs authentication and redirects authenticated users to a

Posted by racl101 on Server Fault See other posts from Server Fault or by racl101
Published on 2010-05-04T03:56:25Z Indexed on 2010/05/04 3:59 UTC
Read the original article Hit count: 288

This is what I have so far but I can't get the RewriteCond and RewriteRule properly.

RewriteEngine On

RewriteCond %{LA-U:REMOTE_USER} (\d{3})$ 
RewriteRule !^%1 http://subdomain.mydomain.com/%1 [R,L].

AuthName "My Domain Protected Area"
AuthType Basic
AuthUserFile /path/to/my/.htpasswd
Require valid-user

This is what I mean the ReWriteCond and RewriteRule to say:

"If the REMOTE_USER has a username ending in 3 digits then capture the three digits that match and for whatever url they are trying to access if it does not start with the 3 digits captured then redirect them to the sub directory with the name equal to those captured three digits."

In other words, if a user named 'johnny202' is authenticated then if he's requesting any directory other than http://subdomain.mydomain.com/202/ then he should be redirected to http://subdomain.mydomain.com/202/

The only thing I can think of that is wrong is the first instance of '%1'.

© Server Fault or respective owner

Related posts about apache

Related posts about mod-rewrite