如何使用htaccess保护Wordpress安装中的目录



我在/root/website/有一个 wordpress 安装位置,在/root/website/subpage/有一个单独的非 wordpress 子页面,所以我可以通过 www.domain.com/subpage 简单地访问它

我想用htaccess文件保护子页面,但在输入登录详细信息后总是收到内部服务器错误(500(。

是否可以有两个htaccess文件,或者我必须编辑Wordpress htaccess文件来保护子页面目录?

我的 Worpress 安装在其根目录中有一个 htaccess,其中包含:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

然后我的子页面目录中有以下 htaccess:

AuthType Basic
AuthName "NameHere"
AuthUserFile /root/website/subpage/.htpasswd
Require valid-user

当然,我已经使用在线生成器设置了一个htpasswd文件。

添加到 public_html 或 publicDirectory 中的 .htaccess 文件:

您可以设置要允许的目录,示例如下:

<Directory /root/website>
# All access controls and authentication are disabled
# in this directory
Satisfy Any
Allow from all
</Directory>
<Directory /root/website/subpage>
AuthType Basic
AuthName "NameHere"
AuthUserFile /root/website/subpage/.htpasswd
Require valid-user
</Directory>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

最新更新