.htaccess,mod_rewrite和基本身份验证

Ima*_*ary 5 wordpress .htaccess mod-rewrite basic-authentication

我正在一个Wordpress网站上工作,我的页面正在使用一个永久链接结构,mod_rewrites看起来像目录.对于几页我想使用基本身份验证来密码保护一些页面.我如何在我的.htaccess文件中写这个?我保护文件或重写的地址吗?

Jon*_*Lin 7

你不需要mod_rewrite,希望这应该可以解决这个问题:

SetEnvIfNoCase Request_URI ^/some/path/to/protect require_auth=true
SetEnvIfNoCase Request_URI ^/another/protected/path require_auth=true

# Auth stuff
AuthUserFile /var/www/htpasswd
AuthName "Password Protected"
AuthType Basic

# Setup a deny/allow
Order Deny,Allow
# Deny from everyone
Deny from all
# except if either of these are satisfied
Satisfy any
# 1. a valid authenticated user
Require valid-user
# or 2. the "require_auth" var is NOT set
Allow from env=!require_auth
Run Code Online (Sandbox Code Playgroud)

mod_auth和mod_env模块应该具有mod_rewrite的预防性,因此你的假目录结构应该保持不变.您只需要SetEnvIfNoCase Request_URI ^/some/path/to/protect require_auth=true为每个填写一个,然后填写其余的auth东西以满足您的需求.