No Access-Control-Allow-Origin 问题解决

No Access-Control-Allow-Origin 问题解决

Font from origin ‘http://www.ingressplus.com’ has been blocked from loading by Cross-Origin Resource Sharing policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://ingressplus.com’ is therefore not allowed access.

 

最近将一个网站迁移到新的VPS,数据库,文件备份后部署遇到了许多奇奇怪怪的问题,但大多都是环境配置问题,由于要在主机部署多个网站,这里用到了VirtualHost.

    DocumentRoot /var/www/html/chyrp
    ServerName www.ingressplus.com
    ServerAlias *.ingressplus.com
    ErrorLog logs/error_log
    CustomLog logs/access_log common

protocolo-http
1.解决403问题后,网站主页可以打开,但所有链接(站内)都404,网站配置问题,使用chyrp重新安装,当然数据库表数据不要删除,文件不要删除,只要在/includes/目录下新生成config.yaml.php 配置文件,是数据库和基本的配置。更改.htaccess 文件:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.+$ index.php [L]
RewriteCond %{HTTP_HOST} !^www.siteX.com [NC]
RewriteRule ^(.*)$ http://www.siteX.com/$1 [L,R=301]

2.网站中特殊字体(social-font)使用带www域名访问正常加载,但使用不带www的域名访问则不加载,通过Chrome调试,看到报错信息:Cross-Origin Resource Sharing policy: No ‘Access-Control-Allow-Origin’ header… 反复查资料更改,通常在使用CDN会出现这种访问权限问题,带www的url和不带www对同一个css同路径文件权限不一样的..在.htaccess 文件添加内容:
<ifmodule mod_headers.c>
<filesmatch “\.(ttf|ttc|otf|eot|woff|font.css|css)$”>
Header set Access-Control-Allow-Origin “*”
</filesmatch>
</ifmodule>
结果无效….将这些内容粘贴到/etc/httpd/conf/httpd.conf 中,重新加载apache.成功解决问题…

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.