【问题标题】:Problem with removing index.php on Codeigniter didn`t load my css and js在 Codeigniter 上删除 index.php 的问题没有加载我的 css 和 js
【发布时间】:2011-09-12 11:40:45
【问题描述】:

目前我试图删除 codeigniter url 上的 index.php。我在 localhost/jqm/withci 上安装了我的 codeigniter。然后我写了 .htaccess 来删除 index.php 并且效果很好。 .htaccess 文件:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /jqm/withci/index.php/$1 [L]

但是我m having some problem, my css file and js wont load.. 我的控制器是

class Home extends CI_Controller {
    function __construct() {
        parent::__construct();
        $this->load->helpers('url');
    }

    function index() {
        $this->load->view('head_view');
        $this->load->view('main_view');
        $this->load->view('foot_view');
    }
}

我对 head_view 的看法是:

<!DOCTYPE HTML>
<html>
  <head>
    <meta name="viewport" content="width=320; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
    <title>jQuery Mobile with Codeigniter</title>
      <link rel="stylesheet" href="<?php echo base_url();?>jquery.mobile/jquery.mobile-1.0a4.1.css" type="text/css" charset="utf-8" />
      <script type="text/javascript" src="<?php echo base_url();?>jquery.mobile/jquery-1.5.2.js"></script>
      <script src="<?php echo base_url();?>jquery.mobile/jquery.mobile-1.0a4.1.js"></script>

    <!-- CDN Respositories: For production, replace lines above with these uncommented minified versions -->
    <!-- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />-->
    <!-- <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>-->
    <!-- <script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>-->

    </head>
  <body>

我尝试使用 base_url() 但它没有t load my css and js. Thank you.. PS : Im 使用 jQuery Mobile 的 css 和 js 文件。我们可以从 CDN 存储库加载它,但我想让它可以从我自己的目录加载,以防我以后想加载自定义 css 或 js

【问题讨论】:

    标签: php codeigniter mod-rewrite


    【解决方案1】:

    在您的 .htaccess 文件中,将包含 JavaScript 和 CSS 的文件夹添加到重写条件中,例如:

    RewriteCond $1 !^(index\.php|images|jquery\.mobile|robots\.txt)
    

    目前这些文件没有加载,而是指向您的index.php 文件。

    【讨论】:

      【解决方案2】:

      尝试将此添加到您的重写规则中,以防止在所有文件和目录上发生重写:

      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      

      【讨论】:

        【解决方案3】:

        您可以在配置文件中设置一个新的配置变量,但在其上设置 css/js 文件的路径

        【讨论】:

          猜你喜欢
          • 2013-12-08
          • 2015-08-10
          • 1970-01-01
          • 1970-01-01
          • 2012-09-30
          • 2016-07-05
          • 2016-05-17
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多