【问题标题】:How to fix CORS issue in Hostgator Shared Hosting [duplicate]如何修复 Hostgator 共享主机中的 CORS 问题 [重复]
【发布时间】:2020-10-02 23:27:48
【问题描述】:

我正在使用第 3 方 API,我从中收到以下错误:

从源“https://mydomain.xyz”访问“https://myapi/..”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否“访问控制允许” -Origin' 标头存在于请求的资源上。

我想知道如何在我的应用程序中启用 CORS 策略。我的 .htaccess 文件是:

<IfModule mod_rewrite.c>

    Header set Access-Control-Allow-Origin "*" // this line I added but no work
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header

    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我正在使用 Laravel 应用程序。提前致谢。

【问题讨论】:

标签: laravel .htaccess laravel-5 cors cpanel


【解决方案1】:

你有没有
添加/激活模块?

a2enmod headers 之后 重启服务

/etc/init.t/apache2 restart

你也可以使用https://github.com/fruitcake/laravel-cors

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-06
    • 2018-08-13
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2018-07-05
    相关资源
    最近更新 更多