dongmou5628 2013-12-11 03:29
浏览 53
已采纳

codeigniter基目录中的css / image / js文件问题

I've been stumbling around setting up the .htaccess file to redirect all requests to the index.php file under xampp in windows 7(removing index.php from the url), and think I may have created an issue for myself...but then again it may be unrelated.

I seem to be having an issue referencing the directories I have setup in the base directory for css, images, and js. I have tracked the issue down, but not sure how to resolve it just yet. If I navigate back a directory ../css/stye.css vs. css/style.css then the stylesheet will load. If I type in the base url or base url with index function call, everything loads as expected:

http://localhost/site
http://localhost/site/home

Now when I add the controller method name

http://localhost/site/home/index

my css is no longer included (until I go into firebug and navigate back a directory)

The code in my .htaccess file (that I found to work with xampp) located in my base directory is as follows:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

I openly admit to not not knowing as much as I probably should about .htaccess files.

CSS href:

<link rel="stylesheet" type="text/css" href="css/jmw.css" />

EDIT

.htaccess file edited as suggested by Rajeev Ranjan

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

I am operating off of the assumption that every view is working as if it where the index.php file itself and accessing directories in this manner. Everything works when using the base_url() function in front of the stylesheet, javascript, or image calls, but I am attempting not to rely on base_url() function in multiple locations of the view file.

  • 写回答

4条回答 默认 最新

  • duanhuan2301 2014-02-09 16:37
    关注

    Finally figured this out! After working with codeigniter for the past few months and gaining a broader understanding about what exactly was going on in the .htaccess file, the solution was obvious. Since the .htaccess file was pointing to the controllers directory, whenever I would attempt to access my images/js/css files from '/images', etc it was looking inside the controllers directory.

    To solve this case I set base_url = '' in config.php and where I call the images/js/css I transverse back a directory '../images/file.png'. Simple solution, just took a bit for my brain to click over :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输