webfont does not apear without www

2019-02-20 10:19发布

问题:

I have tried to find the answer everywhere. I have a sing website www.hugeone.co.uk. When the address is like in this link (with www.) everything is ok. But if I type only hugeone.co.uk webfonts do not appear, and I get the message:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.hugeone.co.uk/includes/templates/huheone/css/fonts/dirtyheadline-webfont.woff. This can be fixed by moving the resource to the same domain or enabling CORS.

my .htaccess file:

RewriteEngine On

# Don't rewrite any URIs ending with a file extension (ending with .[xxxxx])
RewriteCond %{REQUEST_URI} !\.[a-z]{2,5}$ [NC]
# Don't rewrite any URIs for some, popular specific file format extensions,
#   which are not covered by main file extension condition above
RewriteCond %{REQUEST_URI} !\.(mp3|mp4|h264)$ [NC]

RewriteCond %{REQUEST_URI} !^/editors/ [NC]
# Don't rewrite .settings directory
RewriteCond %{REQUEST_URI} !^/\.settings/ [NC]
# Don't rewrite ajax_bin directory
RewriteCond %{REQUEST_URI} !^/ajax_bin/ [NC]
# Don't rewrite artwork directory
RewriteCond %{REQUEST_URI} !^/artwork/ [NC]
# Don't rewrite bigdump directory
RewriteCond %{REQUEST_URI} !^/bigdump/ [NC]
# Don't rewrite bmz_cache directory
RewriteCond %{REQUEST_URI} !^/bmz_cache/ [NC]
# Don't rewrite catal directory
RewriteCond %{REQUEST_URI} !^/catal/ [NC]
# Don't rewrite catdescr directory
RewriteCond %{REQUEST_URI} !^/catdescr/ [NC]
# Don't rewrite ebay directory
RewriteCond %{REQUEST_URI} !^/ebay/ [NC]
# Don't rewrite feed directory
RewriteCond %{REQUEST_URI} !^/feed/ [NC]
# Don't rewrite fonts directory
RewriteCond %{REQUEST_URI} !^/fonts/ [NC]
# Don't rewrite ftp-uploads directory
RewriteCond %{REQUEST_URI} !^/ftp\-uploads/ [NC]
# Don't rewrite harvest directory
RewriteCond %{REQUEST_URI} !^/harvest/ [NC]
# Don't rewrite invoices directory
RewriteCond %{REQUEST_URI} !^/invoices/ [NC]
# Don't rewrite jobs directory
RewriteCond %{REQUEST_URI} !^/jobs/ [NC]
# Don't rewrite logo directory
RewriteCond %{REQUEST_URI} !^/logo/ [NC]
# Don't rewrite londynek directory
RewriteCond %{REQUEST_URI} !^/londynek/ [NC]
# Don't rewrite phpmyadmin directory
RewriteCond %{REQUEST_URI} !^/phpmyadmin/ [NC]
# Don't rewrite populate directory
RewriteCond %{REQUEST_URI} !^/populate/ [NC]
# Don't rewrite temp directory
RewriteCond %{REQUEST_URI} !^/temp/ [NC]
# Don't rewrite test directory
RewriteCond %{REQUEST_URI} !^/test/ [NC]
# Don't rewrite uploads directory
RewriteCond %{REQUEST_URI} !^/uploads/ [NC]
# Don't rewrite very_secret directory
RewriteCond %{REQUEST_URI} !^/very_secret/ [NC]
# Don't rewrite video directory
RewriteCond %{REQUEST_URI} !^/video/ [NC]
# Handle all other URIs using Zen Cart (its index.php)
RewriteRule .* index.php [QSA,L]

## END CEON URI MAPPING REWRITE RULE

#WEBFONTS

AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf
AddType font/woff .woff

<FilesMatch "\.(ttf|otf|eot|woff)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>

I do not know what I can do more.

回答1:

If redirecting all the non-WWW requests to WWW is an option you could do this:

RewriteCond %{HTTP_HOST} ^hugeone\.co\.uk$ [NC]
RewriteRule ^ http://www.hugeone.co.uk%{REQUEST_URI} [R=301,L]

Add that right below:

RewriteEngine On
# optional you might not have the below in your file.
RewriteBase /

In your .htaccess file.

An alternative to the above would be to enable CORS using your .htaccess for webfonts it would be like this:

<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

As a side note its better if your don't use both WWW and non-WWW as Google for instance doesn't like seeing both.



回答2:

Both the url and value should be same.

Two solutions are possible in this case.

  1. Redirecting all the non-www request to www

  2. Changing the base href value based on the url.