2

I am a part time Apache administrator (not by choice). We have an animated gif hit counter. I want to add a CSP to disable active content, but include a CORS policy to allow the gif for the hit counter.

I found an example of adding the CORS policy to .htaccess, but its not the httpd.conf file. How do I take the following .htaccess:

<IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
        <FilesMatch "\.(bmp|cur|gif|ico|jpe?g|png|svgz?|webp)$">
            SetEnvIf Origin ":" IS_CORS
            Header set Access-Control-Allow-Origin "*" env=IS_CORS
        </FilesMatch>
    </IfModule>
</IfModule>

And add it to .httpd.conf?

2

The file format is exactly the same, except as httpd.conf is global, you should put these settings within the apropriate <VirtualHost…> block (and possibly even within a <Path> or <Directory> block to improve performance, as FilesMatch is comparatively slow). For example:

<VirtualHost *:443>
    ServerName …
    OtherSettings …

    <FilesMatch "\.(bmp|cur|gif|ico|jpe?g|png|svgz?|webp)$">
        SetEnvIf Origin ":" IS_CORS
        Header set Access-Control-Allow-Origin "*" env=IS_CORS
    </FilesMatch>
</VirtualHost>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.