php - 相对超链接失败

标签 php html css

我正在为我正在建立的网站使用相对超链接。代码结构如下:

/root/website1/

我所有的代码都在 website1 文件夹下。

网站 1 看起来像:

/css
   style.css
/static
   header.php
   footer.php
   page1.php
page3.php
page4.php

现在,我在 header.php 中使用 style.css 并在 page1.php 中包含 header.php code> 和 page3.php

style.css 如果我像这样使用它,那么两个页面中的任何一个的路径都会失败:

css/style.css

../css/style.css

因为,浏览器会找到与包含它的页面路径相关的 css。有什么方法可以包含 header.php 并使 css 正常工作?

最佳答案

在这种情况下,因为 page1.phppage3.php 不在同一个目录中,所以您需要提供 绝对值urlheader.php 中的 style.css,例如:http://site.tld/css/style.css .

关于php - 相对超链接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23352535/

相关文章:

php - 自定义 serialize_handler 用于自定义 php SessionHandler(数据库存储)

php - 为什么我无法访问我的数据库?

php - 从 mysql 表中分隔逗号分隔值

html - div ID 中的多个无序列表

html - 如何在 Rmarkdown html 输出中有一个 float 图像?

image - 垂直响应图像(最大高度)在 Firefox 中不起作用

html - 从网页打印信封

css - 多个子容器中的第一个 child

php - 通过 PHP 从 C++ 连接到 MySQL 数据库

javascript - 转到顶部按钮在滚动时完全消失