'How to override htaccees file for cache control header

In my company we have htaccess file in which there is no web caching enabled,I want to enable caching for one single api but htaccess file is overriding my cache control that I am setting via header function.Can someone help me please?

htaccess file

<ifModule mod_headers.c>
#BEGIN Security Headers
Header set X-XSS-Protection "1; mode=block"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-Content-Type-Options "nosniff"
#END Security Headers
# BEGIN Cache-Control Headers
#To disable ETags
Header unset ETag
<filesMatch "\.(ico|jpe?g|png|gif|swf|woff)$">
    Header set Cache-Control "max-age=86400, public"
</filesMatch>
<filesMatch "\.(css)$">
    Header set Cache-Control "max-age=7200, public"
</filesMatch>
<filesMatch "\.(js)$">
    Header set Cache-Control "max-age=7200, public"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, no-store, no-cache, must-revalidate, max-age=0"
    Header set Pragma "no-cache"
</filesMatch>
# END Cache-Control Headers

my api php file

    header("Pragma: cache");
    header("Cache-Control: max-age=300");
    header("Expires: " . gmdate("D, d M Y H:i:s", time() + 300) . " GMT");
    header('Last-Modified: ' . gmdate("D, d M Y H:i:s", time()) . ' GMT');
    header('Content-Type: application/json');

response



Solution 1:[1]

There is a property setifempty in apache which works for version>2.2,but for me it was 2.2 so I replaced setifempty with below command

    Header append Cache-Control ""
    Header edit Cache-Control "^$" "private, no-store, no-cache, must-revalidate, max-age=0"
    Header append Pragma ""
    Header edit Pragma "^$" "no-cache"

The above code was edited and it has worked out for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vikas Sharma