处理多个域与Apache的访问控制 - 允许 - 产地标头 [英] handle multiple domains with Access-Control-Allow-Origin header in Apache

查看:285
本文介绍了处理多个域与Apache的访问控制 - 允许 - 产地标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要Apache配置为跨域访问头。我曾尝试多种组合的建议在论坛上的线程数。但它不是为我工作。

I want to configure apache for cross-domain access header. I have tried multiple combination as suggested on number of threads on the forum. But its not working for me.

的方式,我曾尝试:

1)指定不同的线,如下域与头设置

1) Specify domain on different line as below with Header set :

Header set Access-Control-Allow-Origin "example1.com"
Header set Access-Control-Allow-Origin "example2.com"
Header set Access-Control-Allow-Origin: "example3.com"

通过这种设置其采摘的只有最后一个并忽略所有的休息。

With this setup its picking only last one and ignore rest of all.

2)指定不同的线,如下域与头添加

2) Specify domain on different line as below with Header add :

Header add Access-Control-Allow-Origin "example1.com"
Header add Access-Control-Allow-Origin "example2.com"
Header add Access-Control-Allow-Origin: "example3.com"

通过此其显示在头三个领域,但字体没有得到拾起Firefox浏览器。

With this its showing all three domains in header, but fonts are not getting picked up on Firefox.

3)尝试使用 SetEnvIf之后,但同样它不工作:

3.) Tried Using SetEnvIf, but again its not working :

SetEnvIf Origin "http(s)?://(www\.)?(mydomain.com|mydomain2.com)$" AccessControlAllowOrigin=$0$1
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin

最后在与*,但我不希望使用此。

Finally working with "*", but I don't want to use this.

请帮助这一点。

推荐答案

有关3个领域,在你的.htaccess:

For 3 domains, in your .htaccess:

<IfModule mod_headers.c>
    SetEnvIf Origin "http(s)?://(www\.)?(domain1.org|domain2.com|domain3.net)$" AccessControlAllowOrigin=$0$1
    Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
    Header set Access-Control-Allow-Credentials true
</IfModule>

我尝试这样做,它为我工作。让我知道,如果它不给你。

I've tried this and it works for me. Let me know if it doesn't for you.

这篇关于处理多个域与Apache的访问控制 - 允许 - 产地标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆