Allow Verified Users Only To View Directories

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.

Howdy_McGee

Posted 2011-12-01T23:09:05.473

Reputation: 185

Answers

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.

slugonamission

Posted 2011-12-01T23:09:05.473

Reputation: 136

: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 (http://www.colostate.edu/~ric/htpass.html)

– Howdy_McGee – 2011-12-02T00:24:05.667

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 – 2011-12-02T00:25:59.327