且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

访问控制允许原点多原域?

更新时间:2023-01-09 08:23:28

听起来像推荐的做法是让你的服务器读取Origin标题从客户端,将其与您希望允许的域列表进行比较,如果匹配,请将响应中的Access-Control-Allow-Origin标头回溯到客户端的Origin标头的值。

Sounds like the recommended way to do it is to have your server read the Origin header from the client, compare that to the list of domains you'd like to allow, and if it matches, echo the value of the Origin header back to the client as the Access-Control-Allow-Origin header in the response.

使用 .htaccess ,您可以这样做:

# ----------------------------------------------------------------------
# Allow loading of external fonts
# ----------------------------------------------------------------------
<FilesMatch "\.(ttf|otf|eot|woff)$">
    <IfModule mod_headers.c>
        SetEnvIf Origin "http(s)?://(www\.)?(google.com|staging.google.com|development.google.com|otherdomain.net|dev02.otherdomain.net)$" AccessControlAllowOrigin=$0
        Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
    </IfModule>
</FilesMatch>