Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 and but if they go into further folders such as I want to redirect them to a login page. If the user if verified I want them to be able to see 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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
: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 ( – Howdy_McGee Dec 2 '11 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. – slugonamission Dec 2 '11 at 0:25

You must log in to answer this question.

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