Naz,
I use cPanel's Protect Directory function to protect directories. It's just too easy to setup on a production server and setting up a password protection on my test server would be an annoyance.
Please use the [code] ... [/code] wrapper for including code in your posts.
On to your question:
Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.domain.co.uk/store/admin/$1 [R]
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /home/domain/htpasswdlocation/.htpasswd
AuthGroupFile /dev/null
require valid-user
The red off is because {HTTPS} has two values, on and . Yes, that was a {null}. Because of this, you'll either have to change to say !on or use the {SERVER_PORT} to match ^80$ (not SSL, the equivalent of off).
The blue $1 is taking advantage of the atom created by the regex to retain the requested URI and not change to the DirectoryIndex in store/admin (where this .htaccess is located).
The downside to the way that you've attempted is that the password file must be read for every request to admin.
Regards,
DK
Bookmarks