0

We uses KeyCdn to use cdn feature for magento 2. We use push zone for one of our website for testing. KeyCdn working fine except modal popup CORS issue.

We are facing below error.

Access to XMLHttpRequest at 'cdn.xxx.keycdn.net/pub/static/frontend/Abc/xyz/en_US/Magento_Ui/templates/modal/modal-popup.html' from origin 'www.xyz.org' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

enter image description here

I enabled CORS from KeyCdn panel but it was not resolved our issue. We read some blogs to allow CORS in magento 2 and put below code in .htaccess files but it was also not working.

MAGNETO_ROOT/pub/.htaccess

<IfModule mod_headers.c>
    ############################################
    ## Prevent clickjacking
    #Header set X-Frame-Options SAMEORIGIN

    ## Put by developer 
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js|html|json)">
        Header set Access-Control-Allow-Origin "*"
        Header set Access-Control-Allow-Headers "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
        Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
    </FilesMatch>
    ## End
</IfModule>

Please help me, how to resolve CORS issue.

  • Did you try to edit .htaccess of root ? (not pub/.htaccess) – Kishan Patadia Jul 19 at 6:33
  • Hello Kishan thanks for the answer. No I didn't try of root .htaccess. We have domain specific folder so will I put particular domain folder or magento root folder? – Hiren Shah Jul 19 at 6:38
  • You can try in particular domain folder – Kishan Patadia Jul 19 at 6:41
  • I added same .htaccess code in domain folder .htaccess file but not working. Also please see image in main question to identify error. – Hiren Shah Jul 19 at 6:54
  • Try to put that .htaccess code in every domain specific .htaccess files – Kishan Patadia Jul 19 at 10:01
0

Have you taken a look at something like this

https://magento.stackexchange.com/a/172704/70343

But also add html

This is similar to your example so I'm assuming you are running apache.

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.