htaccess的访问控制 - 允许 - 原产地 [英] htaccess Access-Control-Allow-Origin

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

问题描述

我创建一个脚本加载外部的其他网站。它加载CSS和HTML和我自己的服务器上正常工作。

I'm creating a script that loads externally on other sites. It loads CSS and HTML and works fine on my own servers.

然而,当我尝试在其他网站上会显示这个可怕的错误:

However, when I try it on another website it displays this awful error:

Access-Control-Allow-Origin

在这里,你可以看到它加载完美: http://tzook.info/bot/

不过,在这等网站也显示了错误: http://cantloseweight.co/robot/

But on this other website it shows the error: http://cantloseweight.co/robot/

我上传的加载脚本的jsfiddle: http://jsfiddle.net/TL5LK/

I uploaded the loading script to jsfiddle: http://jsfiddle.net/TL5LK/

我试图编辑这样的htaccess文件:

I tried editing the htaccess file like this:

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

或者是这样的:

Or like this:

Header set Access-Control-Allow-Origin *

但它仍然无法正常工作。

But it still doesn't work.

推荐答案

在外部根文件夹的.htaccess试试这个:

Try this in the .htaccess of the external root folder :

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

如果只关注的.js脚本,应包住这上面的code:

And if it only concerns .js scripts you should wrap the above code inside this:

<FilesMatch "\.(js)$">
...
</FilesMatch>

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

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