I have researched this and unfortunately all I can find is general advice on htacesss and pass wording or general htaccess to redirect etc. None of them are what I am after here.
To sum up, we run a set of blogs all using the WordPress Multisite functionality.
All these files etc and info in the database are referenced by an ID and as such the site does not live in a folder.
I want to restrict one folder with a htaccess that our company uses to allow 开发者_如何学编程access to its users.
Normally I would drop that file in the folder and job done.
However, as mentioned there are no physical folders and so I need to somehow add this to the existing htaccess file that WordPress uses to handle everything.
Here is the htaccess file as standard:
RewriteEngine On
RewriteBase /
#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
# deperectaed after upgrade to v. 3.0 RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]
RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>
What I need to add is the following:
AuthName "You must be a valid user"
AuthType Basic
require valid-user
But I only need it to work on one site, say site id=2 for now. I would possibly like to add sites to this later.
Any help will be greatly appreciated.
Cheers
You can use the filesMatch directive to protect the directories. For a site at the path of /foo/ the following should work:
<filesMatch "^foo.*">
AuthName "You must be a valid user"
AuthType Basic
require valid-user
</filesMatch>
To Make sure the filesMatch directive works, try:
<filesMatch "^foo.*">
order allow,deny
deny from all
</filesMatch>
精彩评论