.htaccess PHP 5.3选项中断了Access-Control-Allow-Origin选项?

我先说我正在使用HostGator在共享的
Linux服务器上运行.

我的问题是我的.htaccess中有这行代码:

Header set Access-Control-Allow-Origin *

这允许跨域xhr请求.它一直在工作,直到我的托管服务提供商告诉我添加这个来获取php 5.3(我的程序需要):

# Use PHP 5.3
Action application/x-hg-php53 /cgi-sys/php53
AddHandler application/x-hg-php53 .php

现在我再也无法进行跨域xhr请求了.有谁知道为什么这不再有效? (我确实得到了PHP 5.3)

**更新**

嗯,看起来这不是我的错,也是我无法解决的问题.以下是HostGator技术支持的官方回复:

I’ve examined your site, the error logs, and the .htaccess directives,
and unfortunately I’ve come to the conclusion that the “Header set
Access-Control-Allow-Origin *” line is not compatible with our
implementation of PHP 5.3 as found in our shared servers. I sincerely
apologize for the inconvenience that this causes, but the way we
implement and call PHP 5.3 (since 5.2 is the default and cannot be
altered thanks to cPanel) apparently overrides the Header handling
mechanism, making it not work correctly.

最佳答案 它应该可以一起工作,但是,如果你想提供一个明确设置了头的端点,你也可以用PHP来做:

header('Access-Control-Allow-Origin: *');

在任何输出开始之前将它放入PHP代码中.见header.

点赞