【问题标题】:Header add Access-Control-Allow-Origin "*" causes internal server error标头添加 Access-Control-Allow-Origin "*" 导致内部服务器错误
【发布时间】:2013-06-04 21:40:50
【问题描述】:

我们的资产位于子域中,为了超越我们平台的安全功能,因此我们可以添加 Json 查询,我们必须添加以下 htaccess 代码

<FilesMatch "\.(ttf|otf|eot|woff)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>
Header add Access-Control-Allow-Origin "*"

但是最后一行“Header add Access-Control-Allow-Origin "*"”在我的本地机器上创建了一个内部服务器错误,这很奇怪,因为我们在 prod 环境中没有遇到相同的错误。我们使用的是 Apache 2.2.22 php 5.4.3。

感谢任何帮助。

【问题讨论】:

  • 你检查错误日志了吗?

标签: apache .htaccess


【解决方案1】:

您是否可能没有启用 mod_headers?

其次,我认为您可能希望将 IfModule 块放在 FilesMatch 块之外。像这样

# Allow access from all domains for web fonts
<IfModule mod_headers.c>
    <FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
</IfModule>

代码直接取自https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess#L45

【讨论】:

    猜你喜欢
    • 2018-06-24
    • 2020-10-18
    • 2017-09-05
    • 2011-06-27
    • 2016-07-03
    • 2017-12-16
    • 1970-01-01
    • 2019-05-10
    相关资源
    最近更新 更多