【问题标题】:Codeigniter loads html code when trying to load style.css or a img fileCodeigniter 在尝试加载 style.css 或 img 文件时加载 html 代码
【发布时间】:2013-11-30 11:48:53
【问题描述】:

这是我第一次使用php框架,还没有找到有效的解决方案。

我已经使用asset_helper 文件中的base_url() 正确地使我的页面加载样式标记,并且它似乎工作正常。

生成的代码:

<link rel="stylesheet" type="text/css" href="http://localhost/p_maricarmen/assets/css/style.css" media="screen" />

但它不会加载 css 文件。

我对其他文件也有同样的问题,比如加载带有 img 标签的图像。

我在根目录中也有一个 .htaccess 文件,其中包含代码:

RewriteEngine on
RewriteCond $1 !^(index.php|public|robots.txt)
RewriteRule ^(.*)$ /p_maricarmen/index.php/$1 [L]

用于友好的网址。

更多信息,如果将样式 url 放在我的导航器中,它会生成一个带有 404 错误的 html 页面,页面未创建。

【问题讨论】:

    标签: php codeigniter url load


    【解决方案1】:

    使用以下代码修改您的 .htaccess 文件。

    RewriteEngine on
    RewriteCond $1 !^(index.php|public|assets|robots.txt)
    RewriteRule ^(.*)$ /p_maricarmen/index.php/$1 [L]
    

    您的 css 文件未加载的原因是您必须为放置 css 和 js 文件的文件夹指定重写条件。 您可以对图像文件夹执行相同的操作。 只需指定我为资产指定的图像父文件夹名称,它应该可以按预期工作。

    希望对你有帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 2018-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多