当前位置:web 服务器 > Apache >>

htaccess下配置跨域的方法

允许所有域名跨域

<IfModule mod_headers.c>
   Header add Access-Control-Allow-Origin: *
</IfModule>

指定域名跨域

<IfModule mod_headers.c>
   Header add Access-Control-Allow-Origin: "http://www.yizuotu.com"
</IfModule>

指定多域名跨域

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

</IfModule>


配置文件参考

<IfModule mod_rewrite.c>
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Headers: "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS"
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . index.php
</IfModule>

Apache
IIS
Nginx
Tomcat
如果你遇到web 服务器难题:
访问www.zzzyk.com 试试
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,