【问题标题】:Kohana css images are not appearing after moving site to localhost and href links are not working将站点移动到本地主机后,Kohana css 图像没有出现,并且 href 链接不起作用
【发布时间】:2013-02-26 19:42:57
【问题描述】:

我已经从服务器下载了一个 kohana 项目到 localhost ubuntu 系统。我在 var/www/testsite/ 中为它创建了一个文件夹 我已经按照建议更改了 boostrap.php 中的 Kohana::init

Kohana::init(array(
    'base_url'      => '/testsite/'
    , 'index_file'  => FALSE
    , 'profile'     => ! IN_PRODUCTION
    , 'caching'     => IN_PRODUCTION
));

当我在本地运行站点时,localhost/testsite/ 我看到网站正在加载,但由 css 文件加载的图像没有出现。示例图像的路径是这样的 url("/assets/images/testsite/default/background_all.jpg") 如果我将 url 更改为 url("assets/images/testsite/default/background_all.jpg") 图像会正确显示。

当我点击一个链接时,我会得到

找不到

在此找不到请求的 URL /testsite/contact/info 服务器。 Apache/2.2.22 (Ubuntu) 服务器在 localhost 端口 80

这就是我的 .htaccess 的构造方式,

# Put your installation directory here:
# If your URL is www.example.com/kohana/, use /kohana/
# If your URL is www.example.com/, use /
RewriteBase /testsite/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]

为什么它在服务器上运行而不是在我的本地主机上运行? 如何在不更改 css 文件的 url 路径的情况下解决此问题?

谢谢

【问题讨论】:

  • 这样写url("assets/images/testsite/default/background_all.jpg")有什么问题?
  • 因为在服务器上它的工作方式类似于 url("/assets/images/testsite/default/background_all.jpg") 而不是 url("assets/images/testsite/default/background_all.jpg" )
  • 你可以覆盖url()函数并修复它。
  • 我该怎么做?为什么它在服务器上而不是在我的本地主机上工作?有什么区别?

标签: php kohana


【解决方案1】:

在您的.htaccess 文件的开头添加这一行:RewriteEngine On。这样你就可以开启 URL 重写了。

关于图片:

您应该通过删除'/' 来编辑图像路径,这样您就有了"assets/images/testsite/default/background_all.jpg"。要使其正常工作,您应该包含您的.css 文件,如下所示:URL::site('static/your.css')。所以你的文件夹结构是这样的:包含your.css and assets folder.的静态文件夹

您还应该使用:URL::site('static/img/some_picture.png') 将所有图片加载到应用程序中

【讨论】:

  • 这解决了我的链接不起作用的问题。但是 url() 图像路径仍然不起作用
猜你喜欢
  • 2023-03-22
  • 2013-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-10
  • 2017-12-20
  • 2016-10-24
  • 1970-01-01
相关资源
最近更新 更多