codeigner没有在127.0.0.1上加载css文件

时间:2013-08-04 10:38:00

标签: php codeigniter .htaccess

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

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

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

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

4 个答案:

答案 0 :(得分: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" ?> />

答案 1 :(得分: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>  

在视图中 - &gt;

"<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>"

答案 2 :(得分: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>

等...

答案 3 :(得分:0)

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

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