简体   繁体   English

如何使用htaccess限制一个wordpress网站,但不能限制多网站

[英]How to use htaccess to restrict one wordpress site but not all in multisite

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. 我已经对此进行了研究,但不幸的是,我只能找到关于htacesss的一般建议,并通过措辞或通过htaccess进行重定向等。这些都不是我想要的。

To sum up, we run a set of blogs all using the WordPress Multisite functionality. 综上所述,我们运行了一组全部使用WordPress Multisite功能的博客。

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. 所有这些文件等以及数据库中的信息均由ID引用,因此该站点不在文件夹中。

I want to restrict one folder with a htaccess that our company uses to allow access to its users. 我想用我公司用来允许其用户访问的htaccess限制一个文件夹。

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. 但是,如上所述,没有物理文件夹,因此我需要以某种方式将其添加到WordPress用于处理所有内容的现有htaccess文件中。

Here is the htaccess file as standard: 这是标准的htaccess文件:

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. 但是我只需要它在一个站点上工作,现在说站点id = 2。 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. 您可以使用filesMatch指令来保护目录。 For a site at the path of /foo/ the following should work: 对于位于/ foo /路径的站点,以下方法应该起作用:

<filesMatch "^foo.*">
    AuthName "You must be a valid user" 
    AuthType Basic 
    require valid-user
</filesMatch>

To Make sure the filesMatch directive works, try: 要确保filesMatch指令有效,请尝试:

<filesMatch "^foo.*">
    order allow,deny
    deny from all
</filesMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM