You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Pavel Ustyugov <p....@inets.ru> on 2008/12/15 11:33:44 UTC
RewriteRule / RewriteCond don't interpolate server variables in pattern regex
I have vhost like this structure:
/www/some_host/htdocs - doc root
/www/some_host/htdocs/usr/user1 - user1 dir
/www/some_host/htdocs/usr/user2 - user2 dir
/www/some_host/htdocs/usr/user3 - user3 dir
...
I use authorization for this vhost, and try restrict every
autorized user inside his user dir. User_name correspond with dir_name.
I use next simple .htaccess file for my vhost:
=======================================
Order Allow,Deny
Allow from All
AuthType Basic
AuthName "Some Secured Area"
AuthUserFile /www/some_host/usr.passwd
Require valid-user
Satisfy All
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_USER} !^$
RewriteRule !^usr/%{REMOTE_USER}/ /usr/%{REMOTE_USER}/ [R]
=======================================
If user try to get out from own dir, server forcibly redirect him to correct
dir.
But, this rules don't work, because mod_rewrite not interpolate server
variables in pattern (i see this in log file).
If i use this rules (rule block for every user, without any server
variables), it's work fine:
=======================================
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_USER} ^user1$
RewriteRule !^usr/user1/ /usr/user1/ [R]
RewriteCond %{REMOTE_USER} ^user2$
RewriteRule !^usr/user2/ /usr/user2/ [R]
RewriteCond %{REMOTE_USER} ^user3$
RewriteRule !^usr/user3/ /usr/user3/ [R]
=======================================
But, for hundred users i need write minimum two hundreds rules ... ?!
Why interpolation inside regex not work???
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re[2]: [RESOLVED] RewriteRule / RewriteCond don't interpolate server variables in pattern regex
Posted by Павел Устюгов <p....@inets.ru>.
Hello, Bob Ionescu.
> 2008/12/15 Pavel Ustyugov <p....@inets.ru>:
>> RewriteEngine On
>> RewriteBase /
>> RewriteCond %{REMOTE_USER} !^$
>> RewriteRule !^usr/%{REMOTE_USER}/ /usr/%{REMOTE_USER}/ [R]
>> =======================================
>> If user try to get out from own dir, server forcibly redirect him to correct
>> dir.
>> But, this rules don't work, because mod_rewrite not interpolate server
>> variables in pattern (i see this in log file).
> Use a RegEx internal backreference to compare two values like
> RewriteCond $1<>%{REMOTE_USER} !^([^<]+)<>\1$
> RewriteRule ^usr/([^/]+)/ /usr/%{REMOTE_USER}/ [R]
Huge thanks for greap idea. Genius trick!
I add some additions and obtain work config:
RewriteCond %{REMOTE_USER} !^$
RewriteCond $1<>%{REMOTE_USER} !^([^<]+)<>\1$
RewriteRule ^usr/([^/]+)/ /usr/%{REMOTE_USER}/ [R,L]
RewriteRule !^usr/[^/]+/ /usr/%{REMOTE_USER}/ [R,L]
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: RewriteRule / RewriteCond don't interpolate server variables in pattern regex
Posted by Bob Ionescu <bo...@googlemail.com>.
2008/12/15 Pavel Ustyugov <p....@inets.ru>:
> RewriteEngine On
> RewriteBase /
> RewriteCond %{REMOTE_USER} !^$
> RewriteRule !^usr/%{REMOTE_USER}/ /usr/%{REMOTE_USER}/ [R]
> =======================================
> If user try to get out from own dir, server forcibly redirect him to correct
> dir.
> But, this rules don't work, because mod_rewrite not interpolate server
> variables in pattern (i see this in log file).
Use a RegEx internal backreference to compare two values like
RewriteCond $1<>%{REMOTE_USER} !^([^<]+)<>\1$
RewriteRule ^usr/([^/]+)/ /usr/%{REMOTE_USER}/ [R]
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org