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?

  • are you setting up Magento with Nginx ? – Aditya Shah Sep 28 '18 at 14:10
  • I face same issue. Can you please help me for sort it out ? – Bhavesh Mar 17 at 14:11
0

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

| improve this answer | |
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.

| improve this answer | |

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.