1

嗨,我花了一整天的时间在互联网上搜索 codeigniter 没有加载 css 和 js 文件我修改了 htaccess 规则以启用干净的 url 这里是代码示例 RewriteEngine

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

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT,L] 

该项目在我的电脑上,你能告诉我如何解决这个问题吗

4

4 回答 4

0

最好将所有 CSS、JS 和 img 文件放在应用程序文件夹之外的单独文件夹中。我把它们都放在一个名为“public”的文件夹中然后使用

//Define the base URL
$base_url = $this->config->base_url();

在 HTML

<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>public/css/style.css"/>
<script src="<?php echo $base_url; ?>public/js/js_file.js"></script>

ETC...

于 2013-09-04T19:55:49.437 回答
0

你可以使用这个htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

还要确保你把所有的 css 和 js 文件都放在了/application目录之外

通常:

/root
  /application
  /system
  /css
  /js

然后确保您的 config/config.php 具有:

 $config['base_url']    = 'http://'.$_SERVER['HTTP_HOST'];

你很容易像这样加载css:

<link src="<?php echo base_url(); ?>/css/file.css" ?> />
于 2013-08-04T10:39:45.930 回答
0

这是我的 htaccess 这对我有用

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /sampleappbase/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>  

在视图中-->

"<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>css/bootstrap.css" />"
"<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.min.js"></script>"
于 2013-09-04T19:51:34.003 回答
0

RewriteCond %{REQUEST_FILENAME} 上的 RewriteEngine !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index.php|assets) RewriteRule ^(.*)$ index.php/$1 [L]

如果这不起作用,请检查您的 Xampp 或 Wamp

于 2018-07-04T05:07:04.227 回答