设置访问控制的跨域Ajax请求访问控制、Ajax

由网友(独行者自陶醉)分享简介:我有三个子领域,即 a.xyz.com,b.xyz.com,c.xyz.com。现在,我有大约20 Ajax请求要在身体的onload发 a.xyz.com。 I have three sub-domains namely, a.xyz.com, b.xyz.com, c.xyz.com. Now, I have a...

我有三个子领域,即 a.xyz.com,b.xyz.com,c.xyz.com。现在,我有大约20 Ajax请求要在身体的onload发 a.xyz.com。

I have three sub-domains namely, a.xyz.com, b.xyz.com, c.xyz.com. Now, I have about 20 ajax request to be made on body onload of a.xyz.com.

所以,我认为平均分配20个请求上述三个域之间的。我试了一下穿越这片片段中 b.xyz.com c.xyz.com 中的.htaccess。然而,从a.xyz.com请求任何其他子域仍然被情人抛弃。

So, I thought of distributing 20 requests equally among the three domains above. I tried it through this piece of snippet in .htaccess of b.xyz.com and c.xyz.com. However, the request from a.xyz.com to any other sub-domain is still getting dumped.

<IfModule mod_headers.c>
   <FilesMatch ".(php)$">
    Header set Access-Control-Allow-Origin: http://a.xyz.com,http://b.xyz.com,http://b.xyz.com
    Header set Access-Control-Allow-Methods : POST,GET,OPTIONS
</FilesMatch>
  </IfModule>

我已经把上面的的.htaccess 文件在我的子域 b.xyz.com c.xyz.com

I have placed the above .htaccess file in my subdomains b.xyz.com and c.xyz.com.

所以,任何人都可以predict什么是错在我的方法?

So, can anyone predict whats wrong in my approach ?

谢谢!

推荐答案

试试这个允许跨域所有xyz.com子域:

Try this to allow cross domain on all xyz.com subdomains:

SetEnvIf Origin "http(s)?://(.+.)?(xyz.com)$" ORIGIN_DOMAIN=$0
<FilesMatch ".(php)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin %{ORIGIN_DOMAIN}e env=ORIGIN_DOMAIN
    Header set Access-Control-Allow-Methods "POST,GET,OPTIONS"
  </IfModule>
</FilesMatch>
阅读全文

相关推荐

最新文章