搜索

首页  >  问答  >  正文

PHP:没有“访问控制允许来源”标头存在于请求的资源上

在 .htaccess 中,我将其如下所示。但我不断收到错误。

从源“https://...”访问位于“https:...”的 XMLHttpRequest 已被 CORS 阻止 策略:上不存在“Access-Control-Allow-Origin”标头 请求的资源。

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Origin "PUT, POST, DELETE, GET, OPTIONS"
Header set Access-Control-Allow-Origin "Accept, Authorization, Content-Type"

RewriteEngine On
Options All -Indexes

# ROUTER WWW Redirect.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ROUTER HTTPS Redirect
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ROUTER URL Rewrite
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=/ [L,QSA]

P粉032649413P粉032649413360 天前382

全部回复(1)我来回复

  • P粉593118425

    P粉5931184252024-01-29 09:00:37

    您只能有一个“Allow origin”标头,因此最后一个标头将被解释。

    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "PUT, POST, DELETE, GET, OPTIONS"
    Header set Access-Control-Allow-Headers "Accept, Authorization, Content-Type"

    回复
    0
  • 取消回复