Password protect a subsite in a WordPress network with .htaccess

A wordpress network / multisite setup uses virtual directories.

When you have a wordpress network setup on www.yourdomain.com, you can have multiple blogs with only one WordPress installation, for example:

www.yourdomain.com
www.yourdomain.com/johndoe
www.yourdomain.com/janedoe

Suppose you want to password protect only one subsite e.g. ‘janedoe’, you can’t just create a ‘janedoe’ folder on your webserver with a particular .htaccess in it.

You need to create a secured environment for the virtual folder in your main .htaccess (where all other WordPress rules reside) using the following code:

SetEnvIfNoCase Request_URI "^/janedoe/" SECURED
AuthType Basic
AuthName "restricted area"
AuthUserFile /home/mydomain/.htpasswd
require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=SECURED

4 thoughts on “Password protect a subsite in a WordPress network with .htaccess”

  1. Hi.
    How is if use subdomains.yourdomain.com ?
    Example:
    sub1.yourdomain.com
    sub2.yourdomain.com
    sub3.yourdomain.com

    protect only: sub2.domain.com
    Thanks.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.