三级域名如何开放跨域访问权限

cmy00cmy 发布于 2016/12/18 02:12
阅读 735
收藏 0

现将域名:a.b.c.com通过rewrite,重定向至d.c.com,出现跨域访问错误,提示XMLHttpRequest cannot load http://a.b.c.com/.... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://d.c.com' is therefore not allowed access.

二级域名跨域访问权限已开,apache2.conf已设置如下:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName d.c.com
DocumentRoot /home/...
Header set Access-Control-Allow-Origin *
<Directory "/home/...">
...
</Directory>
</VirtualHost>

跨域访问测试通过。

同样运用到三级域名,测试跨域访问失败:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName  b.c.com
ServerAlias *.b.c.com
DocumentRoot /home/...
Header set Access-Control-Allow-Origin *
<Directory "/home/...">
...
</Directory>
</VirtualHost>


请大神们帮忙分析分析.



加载中
0
cmy00cmy
cmy00cmy
已解决
<Directory "/usr/local/允许跨域访问的资源目录">  
SetEnvIf Origin "http(s)?://(www\.)?(b\.com|c\.com)$" AccessControlAllowOrigin=$0$1  
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin  
Header set Access-Control-Allow-Methods "GET, POST"  
</Directory>



0
cmy00cmy
cmy00cmy

另一种方法,编辑.htaccess

SetEnvIf Origin "^http(s)?://(.+\.)?(domain\.org|domain2\.com)$" origin_is=$0 
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is



返回顶部
顶部