hello, I am using magento 2.4, the application must call a webservice with XMLHTTPRequest, with javascript, the error that appears is: Access to XMLHttpRequest at '***' from origin '***' has been blocked by CORS policy : Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
So I looked on the forums, I modified the file:
/etc/apache2/apache2.conf
In order to add:
<Directory / var / www / html>
Order Allow, Deny
Allow from all
AllowOverride all
Header set Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods "GET, POST, OPTIONS, DELETE"
</Directory>
unfortunately that does not solve my concern, would you have any leads I could use please?
Solved! Go to Solution.
It's good, 👍 I solved my problem 🙂
Hello @alexandred8025
I guess you can resolve this issue by adding this in your .htaccess :
Header add Access-Control-Allow-Origin "b.com"
This will allow the resources to load on the second domain. If you would prefer to allow the resources to load on all domains you can use :
Header add Access-Control-Allow-Origin "*"
Hope it works !
Thanks but it doesn't work, I put it in the .htaccess in:
/var/www/html/.htaccess
The error remains the same in the console.
Do you have another lead please?
The .htaccess file is in root folder of your Magento Project, just change in :
var/www/html/MAGENTO_PROJECT/.htaccess
Let me know if it works !
Yes, it's root folder in var/www/html
Doesn't work for me in .htaccess
Hmmmm, I don't know why, I've been on it for 3 days
curl -X OPTIONS http://www.****.com -i
HTTP/1.1 301 Moved Permanently
Server: nginx/1.16.1
Date: Sun, 11 Oct 2020 17:01:13 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Location: http://infomallorca.es
Please share how you resolved and mark that solution so someone may get help from it
PLease help me i am also facing the same issue