3

I have a .json file that I want to place somewhere in my web folder and serve this if my frontend (another domain) requests it. I can open the file directly but not The problem is, that now I run into CORS problems. Normally if I return something in an action I can set the Headers and the Allow-Origin settings within my php file, but here I just want to get the .json file, nothing else.

I think I need to adjust the .htaccess file within my web directory but so far I was not successful.

I tried adding:

<FilesMatch "\.(json)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>

within /web/.htaccess

Thank you for any hints how I can solve this problem. Cheers

1 Answer 1

1
<FilesMatch "\.(json)$">
    <IfModule mod_headers.c>
        Header add Content-Type "application/json"
        Header add Access-Control-Allow-Methods "GET,HEAD,POST,PUT,DELETE,OPTIONS"
        Header add Access-Control-Allow-Headers "Auth-Token,Content-Type"
        Header add Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>

This seems to work now, although it did not for quite some time. I don't know why but it works now...

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.