3

I tried

 <IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"

and tried for js cross orign from htaccess

<FilesMatch "\.(js)$"> Header set Access-Control-Allow-Origin "*" </FilesMatch> in the .htaccess. but I still have the Cors error. Does anyone know how to fix it?

2
  • are you setting up Magento with Nginx ? Sep 28, 2018 at 14:10
  • I face same issue. Can you please help me for sort it out ?
    – Bhavesh
    Mar 17, 2020 at 14:11

2 Answers 2

1

You can also set the cross-origin in app/etc/env.php by changing the following parameter.

  'x-frame-options' => 'CROSS-ORIGIN',

after changing flush your magento cache

php bin/magento c:f

Thanks

4
0

Go to your site config file for example

nano /etc/apache2/sites-available/localmagento.com.conf

and add

Header set Access-Control-Allow-Origin "*"

as below

<VirtualHost *:80>
     ServerAdmin admin@example.com
     DocumentRoot /var/www/html/magento2/
     ServerName localmagento.com
     ServerAlias www.localmagento.com
     <Directory /var/www/html/magento2/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        Header set Access-Control-Allow-Origin "*"
     </Directory>
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

and use a2enmod headers and then restart server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.