gpt4 book ai didi

apache - 带有 Cloudflare 的 Drupal 7 上的 CORS Access-Control-Allow-Origin 错误

转载 作者:行者123 更新时间:2023-12-04 04:50:46 26 4
gpt4 key购买 nike

我们一直遇到格式错误的问题。

Font from origin 'https://example.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.example.com' is therefore not allowed access.



我们还收到“在原点重定向”错误。

我们正在使用 Drupal 7 和 Cloudflare。

我们试图编辑 .htaccess 以包含
Header set Access-Control-Allow-Origin "https://example.com"
Header set Access-Control-Allow-Origin "https://www.example.com"

尝试了很多;
  • 已清除 cloudflare
  • 重启 apache
  • 尝试通配符“*”
  • Drupal CORS 模块

  • 至今没有喜悦。

    由于这种方法不起作用,我想知道是否遗漏了什么或者是否有其他方法,例如为什么我们得到 origin ' https://example.com ' 通过 Drupal 而不是 ' https://www.example.com 在请求中'。

    最后请注意,当我查看一些资源时,我看到了两种不同的模式。
    如果资源在请求 header 中的状态为“301 Moved Permanently”,则
  • 主机 www.example.com
  • 推荐人 https://example.com/

  • 状态为“304 未修改”的位置
  • 主机 example.com
  • 推荐人 https://example.com/

  • 奇怪的是根本没有任何 www。 htaccess 应该被重定向并且它不在 base_url 中。

    最佳答案

    我遇到了一个非常相似的问题。

    确保启用了模块头

    1 - 要在 Apache2 (httpd) 上启用 mod header ,您需要运行以下命令:

    sudo a2enmod headers



    然后重启 Apache

    sudo service apache2 restart



    2 - 要允许对所有文件的特定源域进行 Access-Control-Allow-Origin (CORS) 授权,请将其添加到您的 .htaccess
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin https://example.org
    Header set Access-Control-Allow-Origin https://example.com
    Header set Access-Control-Allow-Origin https://example.eu
    ## SECURITY WARNING : never add following line when site is in production
    ## Header set Access-Control-Allow-Origin "*"
    </IfModule>

    2 - 允许对特定源域和 进行 Access-Control-Allow-Origin (CORS) 授权仅用于字体 在我们的示例中,在 .htaccess 的以下部分中使用 FilesMatch
    <FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin https://example.org
    Header set Access-Control-Allow-Origin https://example.com
    Header set Access-Control-Allow-Origin https://example.eu
    </IfModule>
    </FilesMatch>

    在 .htaccess 文件中进行更改后,无需重新启动您的 apache 网络服务器

    关于apache - 带有 Cloudflare 的 Drupal 7 上的 CORS Access-Control-Allow-Origin 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33103326/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com