我正在为我正在构建的网站使用相对超链接。代码结构看起来像:
/root/website1/
我所有的代码都在website1文件夹下。
网站1看起来像:
/css
style.css
/static
header.php
footer.php
page1.php
page3.php
page4.php
现在,我在header.php
中使用style.css
,并在page1.php
和page3.php
中包括header.php
。
如果我像一样使用style.css
的路径,那么它对于两个页面中的任何一个都会失败
css/style.css
或
../css/style.css
因为,浏览器会根据包含的页面路径找到css。有没有办法包含header.php
并使css正常工作?
在这种情况下,由于page1.php
和page3.php
不在同一目录上,您需要在header.php
内提供absolute url
到style.css
,例如:http://site.tld/css/style.css
。