InsideDarkWeb.com

Magento 2 Access-Control-Allow-Origin

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?

Magento Asked by Borche Glafche on September 9, 2020

2 Answers

2 Answers

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 [email protected]
     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.

Answered by Hitesh Agrawal on September 9, 2020

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

Answered by Rizwan Khan on September 9, 2020

Add your own answers!

Related Questions

How to setup Magento 2.x with Asynchronous Messaging using Docker

0  Asked on October 2, 2021 by praveen-kumar-s

   

Admin GRID Not Showing Data with ui_component

1  Asked on October 2, 2021 by shoaib-munir

         

Exclude child products from search in magento 2.3.2

0  Asked on October 2, 2021 by rajeev-singh

   

How to update customer information directly in the database

1  Asked on October 2, 2021 by darrell-brogdon

 

Message on category page

1  Asked on October 2, 2021

   

Magento 2.3 adding column to inventory_source

0  Asked on October 2, 2021 by khaled-omara

 

What is meaning of Ui-Component tags in Magento 2

1  Asked on October 2, 2021 by mohit-patel

     

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.