0

Here I have some code in my .htaccess file

<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"

Header set X-UA-Compatible "IE=edge"

# `mod_headers` cannot match based on the content-type, however,
# the `X-UA-Compatible` response header should be send only for
# HTML documents and not for the other resources.

<FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe? 
g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz? 
|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
 Header unset X-UA-Compatible
</FilesMatch>

</IfModule>

on the first line i have the Header set Access-Control-Allow-Origin "*" and it does not seem to be working for any browser except for chrome. I tried using this in my root .htaccess file as well as .htaccess file in app folder. Is there something i am doing wrong? Also I should add that I am using a css @font-face for these google fonts.

1

You will need to create a simple module for this or extend one you have previously made.

app/code/Vendor/Module/etc/module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0"/>
</config>

app/code/Vendor/Module/registration.php

<?php
/**
 * Copyright ©  All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Vendor_Module', __DIR__);

app/code/Vendor/Module/etc/csp_whitelist.xml

<?xml version="1.0"?>
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp/etc/csp_whitelist.xsd">
    <policies>
        <policy id="font-src">
            <values>
                <!--Google-->
                <value id="google-services" type="host">www.googleservices.com</value>
                <value id="google" type="host">*.google.com</value>
                <value id="gstatic" type="host">*.gstatic.com</value>
            </values>
        </policy>
    </policies>
</csp_whitelist>

After you have implemented this this should fix your font issues, please refer to Magento 2 DevDocs - Content Security Policies for further information

2
  • Works fine. Thanks. – Dylan T Sep 10 '20 at 21:22
  • @DylanT glad to hear – Dava Gordon Sep 13 '20 at 21:28

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.