Cross-origin request blocked (CORS) errors have many possible causes. This article applies to the “Cross-Origin Request Blocked error” that is sometimes the result of a Magento multi-store making use of a CDN.
I have set up my Magento (2) multi-store to pull static assets from my Nexcess CDN, but browsers attempting to visit my store present a “Cross-Origin Request Blocked” error in the developer console:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <your_website>
When functioning correctly, cross-origin resource sharing (CORS) allows one site access to another site’s resources despite having different domain names.
When using different hosts (such as a CDN host) to serve portions of your site, you must inform the browser that the third party host is safe to use. Otherwise, the browser assumes the third party host is malicious and blocks it.
To resolve this issue, access your server using SSH and edit the .htaccess file in your website’s root directory as shown below. If you are a Nexcess Classic (non-Cloud) client, you must first enable SSH access. Nexcess Cloud clients have SSH access by default.
In your .htaccess file, insert the line shown below, but replace the angled brackets (<>) and everything between them with the indicated information.
<IfModule mod_headers.c> <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|ico|js|json|html|pdf)$"> Header set Access-Control-Allow-Origin "<customer_origin_domain>" Header set Access-Control-Allow-Headers "X-Requested-With" </FilesMatch> </IfModule>