Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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 (colostate.edu/~ric/htpass.html) –  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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.