How to protect a section of my website?

Hello!

I wanted to protect a section for subdomain of my website https://domywriting.com/ with a password. For that I would like to use .htaccess, but I did not manage to protect only this one part. My only success was to protect the entire site. For this I had used the following code:

AuthUserFile /users/flashlight-photo/www/domywriting/pass/.htpasswd
AuthGroupFile /dev/null
AuthName "flashlight_mitarbeiter"
AuthType Basic
require valid-user

Now my Google search revealed that if I wanted to protect only a part that is in the “protected area” folder and index.html, as well as the entire contents of the “freehand” folder, I should use the following code:

<Directory "/users/subdomain/www/domywriting">
AuthUserFile /users/subdomain/www/domywriting/.htpasswd
AuthGroupFile /dev/null
AuthName "Protected!"
AuthType Basic
require valid-user
</Directory>

<Directory "/users/subdomain/www/freehand">
order allow,deny
allow from all
satisfy any
</Directory>

<files index.html>
order allow,deny
allow from all
satisfy any
</files>

Unfortunately, this did not work …

I hope you can help me!

I’ve tried a similar thing before and ended up figuring out the .htaccess belonged into a different folder, maybe that’s the problem here, too?

In the end I used php for security.

Hi @daisyrowley,

Here’s the relevant part of my virtualhost file for one of my sites I have protected with a password:

<Location />
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /var/www/xxx/.htpasswd
    Require valid-user
</Location>

If you only want to lock down a certain directory on the site, you can edit the <Location> block and use something like <Location /foo/> instead.

2 Likes