6

我在一个站点中使用 HTTP 基本身份验证(用户名和密码),包括托管在 Apache 中的 API 端点,我在 .htaccess 上做这样的事情:

AuthType Basic 
AuthName "Restricted Files"
# (Following line optional)
AuthBasicProvider file
AuthUserFile /usr/local/apache/passwd/passwords
Require user rbowen

由于我在另一个域上托管的页面中从浏览器端使用 API(CORS 部分已经解决),因此我需要允许某些未经身份验证的请求。这些请求是方法为“OPTIONS”的请求,(预检解释如下:http: //www.w3.org/TR/cors/#resource-preflight-requests),请,我不需要任何关于 ajax 或浏览器上的任何其他内容,我需要知道如何在 apache 上执行此操作

提前致谢

4

1 回答 1

9

你可以mod_setenvif在这里使用。

SetEnvIfNoCase Request_Method OPTIONS allowed

AuthType Basic 
AuthName "Restricted Files"
# (Following line optional)
AuthBasicProvider file
AuthUserFile /usr/local/apache/passwd/passwords
Require user rbowen
Order deny,allow
Deny from all
Allow from env=allowed
Satisfy any
于 2014-05-12T20:21:41.837 回答