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>