Foro de elhacker.net

Programación => Desarrollo Web => Mensaje iniciado por: gAb1 en 18 Octubre 2015, 14:18 pm



Título: [Resuelto] fuentes bloqueadas en cliente web - CORS
Publicado por: gAb1 en 18 Octubre 2015, 14:18 pm
Hola buenas, ¿alguien sabe que es eso de CORS? estoy viendo en la consola de firefox que se esta bloqueando las fuentes de mi web (en un hosting, en local funciona bien).

Las fuentes (y css, js, etc) están en un subdominio, ya que las url son procesadas por el index.php y no funcionan las rutas en el dominio.

Citar
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at /fonts/Oxygen-Regular.ttf. (Reason: CORS header 'Access-Control-Allow-Origin' missing). <unknown>
downloadable font: download failed (font-family: "Oxygen-Regular" style:normal weight:normal stretch:normal src index:0): bad URI or cross-site access not allowed source: /fonts/Oxygen-Regular.ttf styles.css:10:12
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at /fonts/Montserrat-Regular.ttf. (Reason: CORS header 'Access-Control-Allow-Origin' missing). <unknown>
downloadable font: download failed (font-family: "Montserrat-Regular" style:normal weight:normal stretch:normal src index:0): bad URI or cross-site access not allowed source: /fonts/Montserrat-Regular.ttf styles.css:6:12
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at /fonts/glyphicons-halflings-regular.woff2. (Reason: CORS header 'Access-Control-Allow-Origin' missing). <unknown>
downloadable font: download failed (font-family: "Glyphicons Halflings" style:normal weight:normal stretch:normal src index:1): bad URI or cross-site access not allowed source: /fonts/glyphicons-halflings-regular.woff2 bootstrap.css:267:12
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at /fonts/glyphicons-halflings-regular.woff. (Reason: CORS header 'Access-Control-Allow-Origin' missing). <unknown>
downloadable font: download failed (font-family: "Glyphicons Halflings" style:normal weight:normal stretch:normal src index:2): bad URI or cross-site access not allowed source: /fonts/glyphicons-halflings-regular.woff bootstrap.css:267:12
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at /fonts/glyphicons-halflings-regular.ttf. (Reason: CORS header 'Access-Control-Allow-Origin' missing). <unknown>
downloadable font: download failed (font-family: "Glyphicons Halflings" style:normal weight:normal stretch:normal src index:3): bad URI or cross-site access not allowed source: /fonts/glyphicons-halflings-regular.ttf bootstrap.css:267:12

He estado leyendo sobre el problema y me parece que hay que activar en el hosting algo sobre CORS pero he estado viendo (en kloxo) y no veo nada parecido.

¿Alguien sabe como solucionar esto?

Gracias!

Edito: Acaba de encontrar la web enable-cors.org pero parece que no funciona... ya he añadido el header al archivo .htaccess (ya que no se como acceder desde kloxo a archivos conf de apache).

Así es como lo tengo actualmente, pero no funciona de ninguna de las maneras (tal vez hay que reiniciar apache o esperar mas?):

Código:
Options -Indexes

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"

DirectoryIndex index.php

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


Título: Re: fuentes bloqueadas en cliente web - CORS
Publicado por: MinusFour en 18 Octubre 2015, 15:27 pm
La instrucción de "Header add" no figura en la documentación de mod_headers.  Solo "Header set". Necesitas también cargar mod_headers (no se si tu hosting lo tenga activado). Este header tiene que ser aplicado sobre la carpeta que tiene el root del subdominio.

Edit: Header add si figura en la documentación pero:

Citar
add
    The response header is added to the existing set of headers, even if this header already exists. This can result in two (or more) headers having the same name. This can lead to unforeseen consequences, and in general set, append or merge should be used instead.


Título: Re: fuentes bloqueadas en cliente web - CORS
Publicado por: gAb1 en 18 Octubre 2015, 15:31 pm
Ah la carpeta root del subdominio... Gracias voy a probar (solo con header set).

Gracias ahora ya funcionan las fuentes!