【问题标题】:CSS is not working in my CodeIgniter Project, But why?CSS 在我的 CodeIgniter 项目中不起作用,但为什么呢?
【发布时间】:2015-04-23 03:30:50
【问题描述】:
My Project Directory at Server address is : ci.xyz.com/ci/h/

I used on my codeigniter project:

$config['base_url'] = './';
$config['index_page'] = '';//index.php

路线为:

$route['default_controller'] = "home/index/";

HtAccess

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /ci/h/
 RewriteCond %{REQUEST_URI} ^system.*
 RewriteRule ^(.*)$ /index.php?/$1 [L]
 RewriteCond %{REQUEST_URI} ^application.*
 RewriteRule ^(.*)$ /index.php?/$1 [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?/$1 [L]

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

当 home 的索引函数(来自路由默认控制器)被加载时,所有资源都在工作。但是,当我单击指向(例如 home/aboutus)的链接时,资源无法正常工作,仅显示文本。我用作链接 echo base_url('home/aboutus');对于资源 echo base_url('assets/theme/css/style.css');

我怎么了?你能建议我关于我的问题吗?

【问题讨论】:

  • 我对codeigniter的了解还不够,无法判断this question中列出的问题是否是这里的问题,但您可以自己阅读。

标签: css .htaccess codeigniter-2 codeigniter-url


【解决方案1】:

我建议使用子域,例如 http://ci.xyz.com 然后 设置 $route['default_controller'] = "home/index/";到 $route['default_controller'] = "home";

打开 application/config/config.php 并将你的 base_url 设置为 $config['base_url'] = 'http://ci.xyz.com/'; // 不要忘记末尾的正斜杠 然后将您的 ROOT/.htaccess 更改为

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

要链接到 ROOT/assets 文件夹中的 CSS 文件,只需使用 assets/theme/css/style.css 之类的东西

【讨论】:

    猜你喜欢
    • 2023-03-27
    • 2019-12-08
    • 2023-04-03
    • 2018-11-12
    • 2020-12-27
    • 2018-05-28
    • 2023-03-31
    • 2021-04-04
    • 1970-01-01
    相关资源
    最近更新 更多