.htpasswd无法正常工作,取消=网站显示

时间:2018-03-22 13:18:53

标签: wordpress .htaccess woocommerce

我正在尝试将.htpasswd转换为Wordpress中的/ shop页面。 它正在工作,弹出来询问当我点击取消然后/商店出现了。 这是我在主要wordpress目录中的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

# Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/shop require_auth=true

# Auth stuff
AuthUserFile (mypath)
AuthName "Password Protected"
AuthType Basic
require valid-user

# 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

有没有办法解决它?

1 个答案:

答案 0 :(得分:0)

我的解决方案是:

AuthName "Protected Area"
AuthType Basic 
AuthUserFile pathtoauth
AuthGroupFile /dev/null

SetEnvIf Request_URI .* noauth
SetEnvIf Request_URI ^/shop !noauth
SetEnvIf Request_URI ^/product-category !noauth
SetEnvIf Request_URI ^/product !noauth

<IfModule mod_authz_core.c>
    <RequireAny>
        Require env noauth
        Require valid-user
    </RequireAny>
</IfModule>

<IfModule !mod_authz_core.c>
    Order Deny,Allow
    Deny from all
    Satisfy any
    Require valid-user
    Allow from env=noauth
</IfModule>

ErrorDocument 401 /error.html
ErrorDocument 403 /error.html

最后两行是关键。这是Wordpress。