Home  >  Q&A  >  body text

PHP: No "Access Control Allow Origin" header is present on the requested resource

In .htaccess I have it as shown below. But I keep getting errors.

Access to XMLHttpRequest at "https:..." from origin "https://..." has been blocked by CORS Policy: 'Access-Control-Allow-Origin' header does not exist on Requested resource.

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粉032649413288 days ago336

reply all(1)I'll reply

  • P粉593118425

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

    You can only have one "Allow origin" header, so the last header will be interpreted.

    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"

    reply
    0
  • Cancelreply