0

I want to upload some websites I have worked on to an Apache server. What I would like to do though is to use an .htaccess file or something similar to redirect the user to a login page if they go beyond a certain folder depth. When logged in I want them to be able to view the directory and go past the main folder directory.

To elaborate further; A user should be able to view www.example.com and www.exmample.com/about.html but if they go into further folders such as www.example.com/folder/index.html I want to redirect them to a login page. If the user if verified I want them to be able to see www.example.com/folder/index.html along with other things.

Any suggestions on how to do this?

I was thinking maybe using .htaccess to redirect to the php page and then edit the .htaccess via PHP if verified but I'm not even sure how to limit folder permissions via the .htaccess file.

1 Answer 1

2

For something like this, you really want to use .htpasswd. This will pop up with a login box and can be configured per-directory.

Failing that, you'll have to redirect all requests to a single PHP script through mod_rewrite, then check authentication, open the requested file and echo it back to the user.

2
  • :S I had no idea .htpasswd existed. Thanks for the suggestion I'll look into how it works. This link seems like what I need (colostate.edu/~ric/htpass.html) Commented Dec 2, 2011 at 0:24
  • Yeah. Sorry if that link I posted isn't too helpful, I've not had to use it in any way for years, I just know of its existence now. Commented Dec 2, 2011 at 0:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .