<pre><code>&lt;FilesMatch &quot;\.(json)$&quot;&gt;
    &lt;IfModule mod_headers.c&gt;
        Header add Content-Type &quot;application/json&quot;
        Header add Access-Control-Allow-Methods &quot;GET,HEAD,POST,PUT,DELETE,OPTIONS&quot;
        Header add Access-Control-Allow-Headers &quot;Auth-Token,Content-Type&quot;
        Header add Access-Control-Allow-Origin &quot;*&quot;
    &lt;/IfModule&gt;
&lt;/FilesMatch&gt;
</code></pre>
<p>This seems to work now, although it did not for quite some time.
I don't know why but it works now...</p>

CC BY-SA 4.0
2023-03-30T10:43:01.630Z
2023-03-30T10:43:01.630Z
Merc
<p>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.</p>
<p>I think I need to adjust the .htaccess file within my <code>web</code> directory but so far I was not successful.</p>
<p>I tried adding:</p>
<pre><code>&lt;FilesMatch &quot;\.(json)$&quot;&gt;
    &lt;IfModule mod_headers.c&gt;
        Header set Access-Control-Allow-Origin &quot;*&quot;
    &lt;/IfModule&gt;
&lt;/FilesMatch&gt;

</code></pre>
<p>within <code>/web/.htaccess</code></p>
<p>Thank you for any hints how I can solve this problem.
Cheers</p>

<htaccess><cors>
How can I serve a .json file from the web folder without CORS problems?
# How can I serve a .json file from the web folder without CORS problems?

(Asked by: username_0 on 2023-03-09)

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:

    
        Header set Access-Control-Allow-Origin "*"
    



within /web/.htaccess
Thank you for any hints how I can solve this problem.
Cheers

**Tags:** htaccess, cors


---

## 1 answers

### Answer by username_0 on 2023-03-30. Score: 1

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 "*"
    


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


---

