Wp-登录时的基本身份验证.htAccess,但允许从WooCommerce注销

时间:2019-11-19 作者:SolaceBeforeDawn

我使用.htaccess 在我的WC网站上进行基本身份验证,以帮助防止黑客访问wp-login, 效果很好。。。除WooCommerce外,如果登录的客户想要从其帐户注销-单击注销链接后,他们会收到基本的身份验证弹出窗口,要求他们“授权”(由我们的.htaccess).

在Woocommerce仪表板上:

您好MrTest(不是MrTest?注销)<<;单击“注销”将打开基本身份验证登录框。。。。我们如何避免这种情况?

以下是htaccess的内容:

<FilesMatch "wp-login.php">
AuthName "Authorized"
AuthType Basic
AuthUserFile /home/user/.pswrdfile
require valid-user
</FilesMatch>
在WooCommerce设置中,注销端点为:customer-logout 注销链接URL显示:

example.com/shop/my-account/customer-logout/?_wpnonce=2e343434
那么如何改变.htaccess 允许wp-login.php?action=logout 通过基本认证?

我试过了,但没有成功;我有最新版本的Apache服务器。

 RewriteEngine On
 RewriteCond %{REQUEST_URI} ^/wp-login.php$
 RewriteCond %{QUERY_STRING} ^action=logout
 RewriteRule ^ - [E=noauth]

 <FilesMatch "^(wp-login.php)">

    Options -Indexes +FollowSymLinks +MultiViews
    AuthName "Protected page. If you are not allowed to be here, leave the page"
    AuthType Basic
    AuthUserFile "/etc/apache2/htaccess/myhtaccess"
    Require valid-user

    Order Deny,Allow
    Deny from all
    Allow from env=noauth

    Satisfy any

 </FilesMatch>

1 个回复
SO网友:Earlee

从中的答案Password protect a specific URL, 我们可以扭转这种状况。引用他的回答,

您应该能够使用mod_env 以及Satisfy any 指令。您可以使用SetEnvIf 对照Request_URI, 即使这不是一条物理路径。然后可以检查变量是否设置在Allow 陈述因此,您需要使用密码登录,或者Allow 无需密码即可进入:

# Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/shop/my-account/customer-logout/ require_auth=false

# 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

相关推荐

WordPress安装目录中缺少.htaccess文件

这发生在我的本地机器Lubuntu 18.04上,带有apache2和Php 7.2.15。尝试的步骤:启用隐藏文件否。看到htaccess文件:https://nimb.ws/4YJfDT<切换permalink结构以尝试强制Wordpress创建新的。htaccess文件(如果缺少)。重新加载文件管理器无变化。https://nimb.ws/eVkKb3<运行终端命令whereis .htaccess列出了许多文件夹,但目标中没有一个文件夹(/var/www/html/wptest2/)。