Forum Moderators: phranque

Message Too Old, No Replies

Using .htaccess to redirect to parent directory if no authentication?

         

JohnKelly

5:10 am on May 18, 2005 (gmt 0)

10+ Year Member



My directory www.domain.com/test/ is password protected, and I have a logging script at www.domain.com/test/index.php, which will log accesses and redirect to www.domain.com/test/dir/ once authenticated.

If someone accesses www.domain.com/test/dir/ directly, they must log in, but since they are not going via the index.php in the parent directory accesses are not logged by my script.

What I want to do is have visitors entering directly via www.domain.com/test/dir/ to be redirected to www.domain.dir/test/ if they are not already authenticated.

Is there a way to do this via .htaccess, without getting an endless loop?

jdMorgan

4:16 pm on May 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to be clear, are you using the script to request/set/track authorization, or are you using Apache mod_auth. If the former, how is the authorized state saved, as a session (cookie) or other?

Jim

JohnKelly

4:48 pm on May 18, 2005 (gmt 0)

10+ Year Member



I'm using Basic Authentication (as with .htpasswd but done via control panel). The www.domain.com/test/ directory is password protected, so any directories under that are too by default.

The PHP script at The www.domain.com/test/index.php is there to track hits, and then redirect to the appropriate directory based on the $_SERVER['PHP_AUTH_USER'] variable. The script does not do any authentication itself, all that is done by Apache.

What I'm trying to do is redirect them back to the script at www.domain.com/test/index.php if they attempt to login directly via www.domain.com/test/dir/ or any other directory under www.domain.com/test/

Sorry for being long-winded, it's sort of hard to explain :)