1

好的,我的 wordpress 网站上有一个区域home/gallery/test,我想使用 .htaccess 限制对它的访问。使用 .htaccess 为目录设置身份验证非常简单。但是我在 wordpress 中的问题是home/gallery/test实际上并不作为目录存在于任何地方,因为我使用的是漂亮的 URL。

因此,虽然我可以将身份验证块粘贴在位于主目录中的 .htaccess 中,但这会请求对整个站点进行身份验证。我不知道在哪里找到 .htaccess 文件以限制对home/gallery/test的访问。

有什么想法吗?我可以在主目录 .htaccess 文件中设置一些内容,以了解它不是整个站点,而只是我想要保护的主/画廊/测试URL?

有关信息,这是我的 htaccess 文件的内容(已更新以包含建议的解决方案)。

SetEnvIfNoCase Request_URI "^/home/gallery/test$" protected

AuthType Basic
AuthName "Forbidden"
AuthUserFile /home/xxxxx/.htpasswd
Require valid-user
Order allow,deny
Allow from all
Deny from env=protected
Satisfy any

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(failed_auth\.html).*$ [NC]
RewriteRule . - [L]
</IfModule> 

# 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
4

1 回答 1

0

有一个解决方案使用mod_setenvif

SetEnvIfNoCase REQUEST_URI "^/home/gallery/test" PROTECTED

AuthType Basic
AuthName "Test protection"
AuthUserFile /path/to/passwords_file
Require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=PROTECTED

编辑:考虑到您的 htaccess 代码,它应该看起来像这样

SetEnvIfNoCase REQUEST_URI "^/home/gallery/test" PROTECTED

AuthType Basic
AuthName "Forbidden"
AuthUserFile /home/xxxxx/.htpasswd
Require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=PROTECTED

# BEGIN WordPress
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteRule ^failed_auth\.html$ - [L]

  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.php [L]
</IfModule>
# END WordPress
于 2014-12-30T12:31:45.753 回答