簡體   English   中英

刪除 Codeigniter 上的 index.php 的問題沒有加載我的 css 和 js

[英]Problem with removing index.php on Codeigniter didn`t load my css and js

目前我試圖刪除 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 won無法加載。我的控制器是

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: I t load my css and js. Thank you.. PS: I正在使用 css 和 jQuery Mobile 的 js 文件。 我們可以從 CDN 存儲庫加載它,但我想讓它可以從我自己的目錄加載,以防我以后想加載自定義 css 或 js

在您的.htaccess文件中,將包含 JavaScript 和 CSS 的文件夾添加到重寫條件,例如:

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

目前這些文件沒有加載,而是指向您的index.php文件。

嘗試將此添加到您的重寫規則中,以防止在所有文件和目錄上發生重寫:

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

您可以在配置文件中設置一個新的配置變量,但在其上設置 css/js 文件的路徑

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM