Forum Moderators: phranque

Message Too Old, No Replies

problem with directory listing

I have problem with rewriterule without an index file.

         

salarcon

2:43 pm on Apr 25, 2007 (gmt 0)

10+ Year Member



Hello,

I Have problems when I config RewriteRule.
I need authenticate users, and that users go yours own directory, All users are in the same directory base.
Once I make a similar configuration:
<Directory /users/www/mydirectory>
AuthName "MyAuth"
AuthType Basic
AuthUserFile path_to_file_users
require valid-user
RewriteEngine On
RewriteRule ^index\.htm$ [mysite.cl...] [R,L]
</Directory>
and this configuration works!, but the difference now is I not have an index file, because must generate directory listing and when try redirect the default index.html of apache, not found in the directory ...

My config is:

<Directory "/home/users">
Options MultiViews +Indexes FollowSymLinks
IndexOptions FancyIndexing
AllowOverride Authconfig
AuthType Basic
AuthName "Ingrese su usuario y clave"
AuthUserFile key_file
Require valid-user
RewriteEngine on
RewriteRule ^/$ [bckup.mysite.cl...] [PT]
I try too with directory but without result
##RewriteRule ^/$ /%{REMOTE_USER}/backup/

The content of each user's dir are theirs backups files (.doc .xls .jpg etc)
The dirs are of form

/home/users/<usuario1>/backup/
/home/users/<usuario2>/backup/

When apache authentificate the users they go to /home/users and they can to see other users.

How can I redirect the inex generated with directory listing?

Thanks for your help
Sylvia

jdMorgan

7:36 pm on Apr 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One thing to keep in mind is that the browser will send the Authorization request header containing the username/password only when it is requesting resources within the "authentication domain." So if the browser requests a page outside that domain it won't send that header, and the REMOTE_USER variable will therefore not be set. So the rule
 RewriteRule ^/$ /%{REMOTE_USER}/backup/ 

(which looks correct) will rewrite to //backup/

You may be able to verify this by testing and examining server access and error logs. For example:

 # Rewrite to blank remote user info page if REMOTE_USER is blank
RewriteCond %{REMOTE_USER} ^$
RewriteRule ^/$ /blank_remote_user_found_page.html
# Else rewrite to user's backup directory
RewriteRule ^/$ /%{REMOTE_USER}/backup/

This will help to determine if it's really a directory-generation-related problem, or an authentication domain problem.

If it is an auth domain problem, and you can't re-define the auth domain or re-structure the "user" subdomains and/URLs to avoid that, then you could set a cookie on the initial "authorize" page, and then use the cookie value as the user navigates around the site:

 RewriteCond %{HTTP_COOKIE} ^user=([a-z0-9_\-]+)$ [NC]
RewriteRule ^/$ /%1/backup/

(This code assumes that the cookie looks like "user=xavier")

You can set cookies with a server-side script, a client-side script, or on Apache 2.x and later, with mod_rewrite.

Jim