Gossamer Forum
Home : General : Perl Programming :

.htaccess Question

Quote Reply
.htaccess Question
Is there a way to modify the .htaccess file such that anyone entering a password protected directory (using .htaccess authentication) is sent to a specific URL within the directory?

For example, say the URL to the password protected directory is:

http://www.myhome.com/members/

And you want all persons first entering that directory first sent to welcome.html regardless of the URL they enter for inside the directory. So if for example, they enter:

http://www.myhome.com/members/
http://www.myhome.com/members/home.html

they are automatically redirected to welcome.html. But not if they follow links within the password protected directory.

Thanks... Dan Smile
Quote Reply
Re: .htaccess Question In reply to
Redirect /members/index.html http://www.myhome.com/members/welcome.html
Redirect /members/home.html http://www.myhome.com/members/welcome.html

[This message has been edited by Eddie (edited June 08, 1999).]
Quote Reply
Re: .htaccess Question In reply to
There's several ways to do it, but none are infallible if you want *every* possible request redirected to welcome.html. What Eddie gave you will only redirect index.html, and any other URL's you choose to set up, it won't catch *every* request the user enters.

And if you set up a "catch-all" Redirect, or do the same thing with mod_rewrite, you'll be setting up a loop, because the server will try and rewrite the welcome.html page as well. And everything else you have in the protected directory! Smile

The only real solution would be to rewrite the URL to another directory somewhere else, which kind of defeats the purpose.

Sorry!
adam

[This message has been edited by dahamsta (edited June 08, 1999).]
Quote Reply
Re: .htaccess Question In reply to
Thinking about it afterwards, there may be some way of doing it using regular expressions and mod_rewrite, or an external rewrite map. But it's the Apache pro's you'll need to talk to, mod_rewrite is one of the more complimicated (yes, I did that on purpose Smile) of the Apache modules. Try joining the Apache mailing list for a couple of days and asking there.

www.apache.org

adam
Quote Reply
Re: .htaccess Question In reply to
Thanks all. But I have a solution:

1. Add the following code to the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com/index.html [NC]
RewriteCond %{HTTP_COOKIE} !(^|(.+ Wink*)id=valid(;.*|$)
RewriteRule /* http://www.yourdomain.com/index.html [L,R]

The URL specified in the RewriteRule is the jump page (outside the members directory) and it has a link to the target page in the members directory.

2. Add the following code to the bottom of the target page:

<script language="javascript">
document.cookie = "id=valid; path=/"
</script>

If someone first accesses the members directory but not through the jump page or if they go to any other page other than the target page, they are redirected to the jump page which then takes them to the target page when they follow a link.

I tested it and it seems to work.

Dan Smile
Quote Reply
Re: .htaccess Question In reply to
See! Told ya mod_rewrite was complicated! Smile

I thought that cookies might be a solution alright, but cookies are one of my (many) weak points. Did you figure it out yourself ot did you find it somewhere on the web? If you found it on the web, I'd love to know where, I like playing with mod_rewrite.

Congrats for figuring it out anyway...

adam
Quote Reply
Re: .htaccess Question In reply to
I cannot take credit for this solution. I hijacked it from the resources page of my server who just developed it. It can be found at http://www.xcite.net/resources/index.html .

However, there is no other help regarding mod_rewrite.

Dan Smile
Quote Reply
Re: .htaccess Question In reply to
Thanks Dan.

adam