codeigniter通过lan-break-css fontfamily访问应用程序的动态baseurl


codeigniter Dynamic baseurl to access app via lan break css fontfamily

问题是我想从wifi网络上的其他设备访问我的代码点火器应用程序,我注意到所有css中断;所以我把base_url编辑成

config.php

$config['base_url']= "http://".gethostbyname($_SERVER['SERVER_NAME'])."/ehit";

我的.htaccess是

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index'.php|assets|img|css|js|robots'.txt|favicon'.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

现在,当我从等其他设备打开我的应用程序时,一切都加载正确

除fontsAwsome外的http://192.168.1.61/ehit

html源

<!-- Core CSS -->
    <link rel="stylesheet" type="text/css" href="http://127.0.0.1/ehit/assets/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="http://127.0.0.1/ehit/assets/css/googlefont.css">
    <link rel="stylesheet" type="text/css" href="http://127.0.0.1/ehit/assets/css/font-awesome.css">

没有定义fontfamily正确的所有负载。在font-awesome.css中我找到

@font-face {
  font-family: 'FontAwesome';
  src: url('../fonts/fontawesome-webfont.eot');
  src: url('../fonts/fontawesome-webfont.eot') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff') format('woff'), url('../fonts/fontawesome-webfont.ttf') format('truetype'), url('../fonts/fontawesome-webfont.svg') format('svg');
  font-weight: normal;
  font-style: normal;
}

所以CCD_ 2可能是问题所在;有办法解决它吗?

我调试并发现url是正确的仍然字体家族FontAwesome不在

curl 'http://127.0.0.1/ehit/assets/fonts/fontawesome-webfont.woff' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.5' -H 'Cache-Control: max-age=0' -H 'Connection: keep-alive' -H 'Host: 127.0.0.1' -H 'Origin: http://localhost' -H 'Referer: http://127.0.0.1/ehit/assets/css/font-awesome.css' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0'

那么问题出在哪里呢?

编辑

当我将$config更改为时解决了问题

//$config['base_url']= "http://".gethostbyname($_SERVER['SERVER_NAME'])."/ehit"; //old
$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

那么问题出在哪里呢?

到application/config/config.php将localhost更改为您的IP地址
访问您IP地址上的所有站点

示例:
$config['base_url']='http://192.168.xx.xx/codeigniter-project/'

PC  192.168.xx.xx/codeigniter-project<br>
Mobile 192.168.xx.xx/codeigniter-project<br>

tablet  192.168.xx.xx/codeigniter-project<br>

祝你好运。

您需要允许.htaccess:中的.woff文件

RewriteCond $1 !^(index'.php|assets|woff|eot|img|css|js|robots'.txt|favicon'.ico)

这可能是一个原因。