0

I have upgraded my website from magento 2.4.3 to 2.4.5 and now I am getting the issue Access to XMLHttpRequest at from origin has been blocked by CORS policy issue

I have a multi store setup and have tried a number of solutions. These are the URLs of my store

https://www.website.com/ (Default store)
https://www.website1.com/
https://www.website2.com/

I am getting this issue on

https://www.website1.com/ and 
https://www.website2.com/

Default store i.e https://www.website.com/ is working fine

I have tried a multiple solutions that I found online, but none of them worked for me.

This is the rule that I have in .htaccess file

<IfModule mod_headers.c>
############################################
Header set X-UA-Compatible "IE=edge"

# `mod_headers` cannot match based on the content-type, however,
# the `X-UA-Compatible` response header should be send only for
# HTML documents and not for the other resources.
<FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
    Header unset X-UA-Compatible
</FilesMatch>
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|json|html)$">
    Header always set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Headers "X-Requested-With"
    Header always set Access-Control-Allow-Methods "GET"
    Header always set Access-Control-Allow-Headers "X-Accept-Charset,X-Accept,Content-Type"

</FilesMatch>

</IfModule>

Also I have added CORS Origin URL in magento admin that is responsible for as https://www.website.com/ that is responsible for serving static content.

enter image description here

I can not think of any more solution. I am really stuck with this and this problem we are having with our production website. Could some one guide me to solve the issue.

I also have added the urls for reference and one can see the issue in the browser console tab.

I highly appreciate any guidance to solve this issue.

3
  • Please check my answer regarding the CORS issue. It may help you. magento.stackexchange.com/questions/363860/… Commented May 17, 2023 at 15:44
  • I tried solution 1 from the above link but it did not worked. Commented May 17, 2023 at 18:36
  • I tried solution 1 from the above link but it did not worked. ALso you can see the screenshot that implement the your Solution2. It is the screenshot from the same module mentioned in the SOlution 2 but it is also not working. Really stuck with this after the upgrade. Commented May 17, 2023 at 18:57

1 Answer 1

0

I also have same issue a few years ago, Magento 2 CORS issue

in my case, I have custom code on my index.php and affect the multidomain setup. make sure that you use default magento code on your files, seems magento does not have cors issue instead we miss some configuration that trigger that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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