gpt4 book ai didi

apache - 排除重写目录以进行保护

转载 作者:行者123 更新时间:2023-12-02 03:23:32 25 4
gpt4 key购买 nike

我们安装了 magento。由于开发目的,我们用 .htacces 保护关闭了它。但我确实想打开 API,这样我就不必将一堆第 3 方服务列入白名单。

下面的结构适用于存在的文件 (api.php) 但不适用于重写的 url (api, api/?wsdl).

这个 .htaccess 是 public_html 之上的一个目录。基于perishablepress

AuthType Basic
AuthName "Toegang nodig? neem gerust contact op: 038-8200270 !"
AuthUserFile /home/kijken/domains/.htpasswd
AuthGroupFile /dev/null
Require valid-user
# allow public access to the following resources
SetEnvIf Request_URI "^/api.php" allow
SetEnvIf Request_URI "^/api/" allow #api is not a real folder
SetEnvIf Request_URI "^/api/?wsdl" allow

Order allow,deny
Allow from env=allow

Allow from 217.121.158.248 #Company HQ

Satisfy any

Magento 及其 .htaccess 在 public_html 中,mirror文件的

我需要更改什么才能使其适用于不存在的文件?
只要满足以下 3 个条件,我不介意不同的设置:

  1. 白名单IP(目前有效)
  2. 登录其他IP(目前有效)
  3. 排除某些 URL(根本问题)

最佳答案

查看您的设置并按照您的解释,最简单的方法是将您的限制代码放在Magento htaccess 的顶部(/public_html/.htaccess)。

I've pasted it above the rest of the magento .htacces inside the public_html. Nothing changes about my question. The problems stay the same.

那是因为 Magento 的 htaccess 删除了您的限制。您需要删除这两行:

enter image description here

另一个细节
SetEnvIf Request_URI "^/api/?wsdl"allow 没用,因为:

  1. 查询字符串部分(此处为wsdl)未包含在Request_URI中(与您的期望不符)
  2. 之前的规则(SetEnvIf Request_URI "^/api/"allow)更大并且包含了你没用的规则

结论
您的最终代码应如下所示

SetEnvIf Request_URI "^/api\.php$" allow
SetEnvIf Request_URI "^/api/" allow

AuthType Basic
AuthName "Toegang nodig? neem gerust contact op: 038-8200270 !"
AuthUserFile /home/kijken/domains/.htpasswd
AuthGroupFile /dev/null
Require valid-user
Order allow,deny
Allow from env=allow
Allow from 217.121.158.248
Satisfy any

# Magento htaccess code here

测试和工作

关于apache - 排除重写目录以进行保护,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31608506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com