图像路径问题

时间:2013-05-10 12:48:55

标签: css image codeigniter

我有一个用CodeIgniter构建的项目。在我的localhost中,该网站工作正常,但在远程服务器中,无法从CSS& JS。

该网站是子域中的访客。服务器文件系统层次结构为:

--/
---apps (subdomain folder for my app)
----application
----[other CI forlders]
----css
----js
----img
--[other web folders (no CI)]
--index.html

在CSS文件中,我用这种方式定义图像路径:“../ img /” 例如:

#maincontainer {background-image: url('../img/main_bg.gif');}

但是,在Chrome和FF中,显示错误以加载资源:

  

无法加载资源:服务器响应状态为404   (未找到)http://apps.manantiales.edu.ar/img/main_bg.gif

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

您在子域中,因此,正确的路径是:

http://manantiales.edu.ar/apps/img/main_bg.gif

  1. 您可以使用htaccess文件中的规则来使子域路径起作用 或
  2. 只需使用像diEcho建议的绝对路径。你可以在这样的css文件中嵌入php代码:

    maincontainer {background-image:url('<?php echo site_url('img / main_bg.gif');?>');}

  3. (我在<?php中添加了一个额外空格,因为不知道如何格式化它以便在这里正确显示)

答案 1 :(得分:0)

你可以像这样做

--/
---apps (subdomain folder for my app)
----application
----[other CI forlders]
--[other web folders (no CI)]
--index.html
--css
--js
--img

#maincontainer {background-image: url('../img/main_bg.gif');}

和html文件;

<?= base_url();?>css/css.css