php - 我的 htaccess 文件无法加载 css

标签 php html css .htaccess codeigniter

我试图找到一些答案,但它对我不起作用,所以我决定在这里问: 我是 codeigniter 的新手,在观看了一些教程后,我最终得到了这个 .htaccess 代码。

 <IfModule mod_rewrite.c>
      RewriteEngine On

  RewriteBase /myprojectname
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index.php|css|robots.txt)
  RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
 ErrorDocument 404 /index.php
</IfModule>

我在本地主机上使用 xampp,我的问题是我无法在我的 View 中加载我的 css

 <link rel="stylesheet" href="css/metro-bootstrap.css">

实际上我在 RewriteCond $1 !^(index.php|css|robots.txt) 中包含了 css 根看起来像这样

/
-application
-css
-js
-font
-system
-.htaccess
-index.php

最佳答案

您不必在该行中包含 css 和 robots.txt,因为 RewriteCond %{REQUEST_FILENAME} !-f处理它(基本上它说如果它不是文件则重写 - '!-f' 部分),实际上你可以删除 RewriteCond $1 !^(index.php|css|robots.txt) .如果你的 css 仍然不起作用,请使用 <?php echo base_url();?>css/metro-bootstrap.css这行代码,base_url()表示元素中的基本路径。

关于php - 我的 htaccess 文件无法加载 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26654042/

相关文章:

php - 在 yii2 中向 Controller 发送表单数据的问题

javascript - 本地网络中的 mac 地址(JavaScript 或 PHP)

javascript - 如何使用 jQuery 在电子邮件验证上的按键上添加另一个语句

javascript - 使用 jQuery 显示没有特定类的随机 div

css - 我在一行中有 3 个 div,如何让中间的 div 保持精确的宽度,而随着屏幕尺寸变小,左右 div 缩小?

javascript - Twitter Bootstrap 的下拉菜单不起作用——无法展开

javascript - 如何在滚动时使元素随视口(viewport)滑动?

php - Laravel CRUD Controller 测试

php - 使用带有 GUID 和命名空间的 PHP 读取 Web 服务

javascript - 永远不会到达我的函数调用 - ReactJs 0.12.0