Php 代码点火器+;CSS工作不正常,可能是baseurl

Php 代码点火器+;CSS工作不正常,可能是baseurl,php,css,.htaccess,codeigniter,Php,Css,.htaccess,Codeigniter,这个问题已经被问了好几次了,但我研究了一下,还是解决不了。在我的一个视图文件中,我有(参考我的css): css文件位于: - www - application - view - css - screen.css - system 我还尝试在-www下的同一文件夹中设置css,并通过 link rel="stylesheet" type="text/css" href="css/screen.css" 我的基本url设置为”,因为我在本地开发。

这个问题已经被问了好几次了,但我研究了一下,还是解决不了。在我的一个视图文件中,我有(参考我的css):

css文件位于:

- www
  - application
    - view
      - css
        - screen.css
  - system
我还尝试在
-www
下的同一文件夹中设置css,并通过

link rel="stylesheet" type="text/css"  href="css/screen.css"
我的基本
url
设置为
,因为我在本地开发。这就是问题所在吗?我正在使用wamp服务器


那么问题是什么呢?有人可以帮忙吗?

您不能将CSS文件或要提供给浏览器的文件放在应用程序文件夹中,因为出于安全原因,.htaccess文件设置为“拒绝来自所有人”,您的CSS、JS、图像文件等需要位于应用程序文件夹之外

将CSS文件放在“www”文件夹中名为“CSS”的文件夹中,使其不在“应用程序”或“系统”中。然后确保使用以下内容(请注意前导斜杠,表示绝对URL):

改用这个:

# If your default controller is something other than
# "welcome" you should probably change this
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

记住,给猫剥皮有几种方法

快速修复而不影响htaccess。 使用基本url()或站点url():


您应该将所有资产文件(图像、js、css等)放在站点根目录上的单独文件夹中(应用程序文件夹之外)。
创建名为“文件”的文件夹,并在站点根目录上的
.htaccess
文件中添加以下行:

# Allow these directories and files to be displayed directly:
# - index.php (DO NOT FORGET THIS!)
# - robots.txt
# - favicon.ico
# - Any file inside of the files/ - js/, or css/ directories
RewriteCond $1 ^(index\.php|files)

这样,您就可以通过url直接访问该文件夹(以及其中的任何文件夹)。

我在Windows中也遇到了同样的问题。在Mac中,这很容易。 当试图从URL中排除
index.php
时,我遇到了
400错误请求错误
。 后来,通过在slash RewriteRule index.php前面加前缀,修复了这个问题,如下所示

RewriteRule ^(.*)$ index.php/$1 [L]

继续前进,面临另一个问题: 无法加载资源/静态文件。此外,我的资产文件夹位于根目录级别。 我看到了一个解决方案,比如在RewriteCond中添加“assets”,使其无法应用rewriteRule。像

RewriteCond $1 !^(index\.php|assets)       #It does not work for me
但是,它不起作用。我得到404找不到错误。 后来,我找到了解决方案,如

RewriteCond $1 !^(index\.php|\/assets)     #Working!
我的重写脚本如下:

  RewriteEngine on
  RewriteCond $1 !^(index\.php|\/assets)
  RewriteRule ^(.*)$ /index.php/$1 [L]

希望,这将有助于节省大量时间!:)

@cryptic你其实错了。只要加载了URL帮助程序,base_URL()就会尊重它的名称并很好地返回…基本URL。无论如何,谢谢你的否决票。同意,我更喜欢这种方式,把URL变成一个永久的URL,而不是一个相对的URL。据我所知,这是更好的搜索引擎优化方法,可以省去很多麻烦。link rel=“stylesheet”type=“text/css”href=“localhost/assets/css/screen.css”这就是浏览器中显示的内容。我有资产文件夹。@AaronSantos如果在资产文件夹中我有一个JS子文件夹,如果我有一个文件,比如script.JS,我想调用该文件的base_url()?既然它在应用程序文件夹之外,你知道怎么做吗?link rel=​“样式表”类型=​“文本/​css“href=​"/​css/​“screen.css”不起作用。这就是我的Google Chrome浏览器在使用web工具时显示的内容。这是在你将文件移动到webroot文件夹“www”中一个名为“css”的文件夹之后。是的,我在www文件夹下有一个css文件夹。我检查元素并查看http请求头,这就是显示的内容:http://localhost/css/screen.csw当您访问时,是否会出现404403500等错误?重新启用它,但注释掉这些行#如果您的默认控制器不是#“欢迎”的,您可能应该更改此RewriteCond$1^(index\.php |文件)RewriteRule^(.*)$index.php?/$1[L]RewriteRule^(.*)$/index.php?/$1[L]我有一个名为css的文件夹,其中存储并更改了应用程序重写引擎。当我输入http://localhost/assets时,它不起作用,它给了我一个404。顺便说一句,我的base_url='',我正在本地开发,如果这很重要的话。好吧,看看我是否理解正确,您在本地主机的根目录中有一个名为“assets”的文件夹,在.htaccess文件中有一个“assets”重写条件,您仍然会得到404错误吗?这是我的重写引擎。我仍然可以;无法使用url访问资产文件夹。在www文件夹下,我有-assets、-appliaction和-systemOk,然后改为
RewriteCond$1^(index\.php | files)
您添加的行,试试这行
RewriteCond$1^(index\.php | assets)
,然后尝试访问仍然404,url自动从localho st/assets更改为htp://localhost/assets/?/assets
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond $1 !^(index\.php|assets)       #It does not work for me
RewriteCond $1 !^(index\.php|\/assets)     #Working!
  RewriteEngine on
  RewriteCond $1 !^(index\.php|\/assets)
  RewriteRule ^(.*)$ /index.php/$1 [L]