从apache或htaccess禁用Access-Control-Allow-Origin

时间:2018-02-06 22:54:28

标签: apache .htaccess cpanel

在我的本地计算机上,当我尝试使用跨域通过ajax发送请求时,请求无法完成。我将此选项添加到我的.htaccess文件中:

Header always set Access-Control-Allow-Origin "https://accepted-domain"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"

RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L] 

之后,一切正常,但当我将其上传到我的cPanel服务器时,请求没有完成。 但是,如果我从.htaccess文件中删除这些行,一切正常。

问题是:如何在我的cPanel主机中禁用此Access-Control-Allow-Origin,以使用我想要接受的域来定义它?

已更新 当我在我的cPanel主机上发送请求时,响应是这条消息:

Failed to load http://receiver-domain.com/create.php: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Origin 'http://sender-domain.com' is therefore not allowed access.

这意味着Access-Control-Allow-Origin已设置在其他位置。

0 个答案:

没有答案