Refused to apply style from ' url ' because its MIME type ('text / html')
у меня есть следующая проблема при загрузке assets
на сайт, который я загрузил на 000webhost
Refused to apply style from 'https://ucrmreportcustom.000webhostapp.com/ucrm_client_report/webassets/css/ligne.css' потому что its MIME type ('text/html') is not supported stylesheet MIME type, and strict MIME checking is enabled.
это сайт: https://ucrmreportcustom.000webhostapp.com/ucrm_client_report/clientes/todosClientes/
дело в том, что это собственный фреймворк PHP, я генерирую url-адреса assets
следующим образом;
<link href="<?= Assets::setAssets('css/ligne.css') ?>" rel="stylesheet" type="text/css">
<link href="<?= Assets::setAssets('css/font-awesome.css') ?>" rel="stylesheet" type="text/css">
это возвращает мне следующее;
<link href="https://ucrmreportcustom.000webhostapp.com/ucrm_client_report/webassets/css/ligne.css" rel="stylesheet" type="text/css">
<link href="https://ucrmreportcustom.000webhostapp.com/ucrm_client_report/webassets/css/font-awesome.css" rel="stylesheet" type="text/css">
Assets::setAssets
/**
* Recibe un string con el elemento que se pretende agregar al proyecto
* eje: 'css/main.css'
* eje: 'js/jquery.min.js'
* Este retorna una url absoluta
* Tiene parametro opcional para determinar si se permitida que el navegador
* almacene la cache de los assets
*
* @param $asset
* @param bool $cache
* @return string
*/
static public function setAssets($asset,$cache = true)
{
$domain = $_SERVER['SERVER_NAME'];
$assets_dir = 'webassets';
return PROTOCOL . '://' . $domain . '/' . self::root_dir() . '/' . $assets_dir . '/' . $asset . self::cache($cache);
}
/**
* Retorna el nombre de la carpeta base del proyecto
* esto es relativo ya que la carpeta donde esta el framework podria
* llamarse de cualquier manera y con esto se obtiene este nombre para
* hacer referencia a los assets
*
* @return string
*/
static private function root_dir(){
$root_dir = $_SERVER['REQUEST_URI'];
$root_dir = explode('/',$root_dir);
return $root_dir[1];
}
/**
* Se utiliza para retornar el tiempo a la url de los assets para
* evitar que el navegador almacene estos en cache
*
* @param $bool
* @return string
*/
static private function cache($bool){
if(!$bool){
return '?' . time();
}
}
я пробовал следующее без успеха;
- Добавить
<base href="/">
перед всеми assets - разместить URL абсолютное
- переместить файлы в другой каталог
- изменить тип mime на
text/html
мое последнее письмо-спросить сообщество.
редактирование:
на местном уровне это работает отлично, даже я могу получить доступ к assets с помощью url;
http://localhost/ucrm_client_report/webassets/css/ligne.css
2 answers
Если вы откроете свою страницу с помощью консоли, вы увидите, что CSS и JS не загружаются. Ни один. Они дают ошибку 404
, и сервер отправляет небольшую HTML-страницу, сообщающую об ошибке, в результате чего mime type установлен на text/html
.
Попробуйте загрузить эту ссылку, и вы увидите, что она не работает:
Https://ucrmreportcustom.000webhostapp.com/ucrm_client_report/webassets/css/ligne.css
Я уже исправил это, проблема в том, что сервер чувствителен к регистру;
Папка webassets
у меня есть с заглавной буквой W на сервере.