深圳市某某有限公司

一句话企业宣传语

繁体 简体中文 | 信息管理

案例展示

联系我们

公司电话:010-88888888
公司传真:010-88888888
电子邮箱:info@youname.com
联 系 人:某某先生 (总经理)
公司地址:北京市西城区复兴门外大 街某某大厦88号

技术相关

技术相关

相对路径和绝对路径区分

来源: 时间:2012-03-29 14:37:31 浏览次数:

HTML相对路径(Relative Path)
同一个目录的文件引用,如果源文件和引用文件在同一个目录里,直接写引用文件名即可。

案例一:
我们现在建一个源文件info.html,在info.html里要引用index.html文件作为超链接。
html路径是:c:\Inetpub\wwwroot\sites\.
假设info.html路径是:c:\Inetpub\wwwroot\sites\mf1288\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\mf1288\index.html
在info.html加入index.html超链接的代码应该这样写:<a href = "index.html">index.html</a>
如何表示上级目录?
HTML初学者会经常遇到这样一个问题,../表示源文件所在目录的上一级目录,../../表示源文件所在目录的上上级目录,以此类推。

案例二:
假设info.html路径是:c:\Inetpub\wwwroot\sites\mf1288\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\index.html
html路径是:c:\Inetpub\wwwroot.
在info.html加入index.html超链接的代码应该这样写:<a href = "../index.html">index.html</a>

案例三
假设info.html路径是:c:\Inetpub\wwwroot\sites\mf1288\info.html
假设index.html路径是:c:\Inetpub\wwwroot\index.html
在info.html加入index.html超链接的代码应该这样写:<a href = "../../index.html">index.html</a>

案例四
假设info.html路径是:c:\Inetpub\wwwroot\sites\mf1288\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\wowstory\index.html
在info.html加入index.html超链接的代码应该这样写:<a href = "../wowstory/index.html">index.html</a>
如何表示下级目录? //www.mf1288.com/tutorials.
引用下级目录的文件,直接写下级目录文件的路径即可。

案例五:
假设info.html路径是:c:\Inetpub\wwwroot\sites\mf1288\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\mf1288\html\index.html
在info.html加入index.html超链接的代码应该这样写:<a href = "html/index.html">index.html</a>

案例六:
假设info.html路径是:c:\Inetpub\wwwroot\sites\mf1288\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\mf1288\html\tutorials\index.html
在info.html加入index.html超链接的代码应该这样写:<a href = "html/tutorials/index.html">index.html</a>

HTML绝对路径(Absolute Path)
HTML绝对路径(absolute path)指带域名的文件的完整路径。
1)假设你注册了域名www.mf1288.com,并申请了虚拟主机,你的虚拟主机提供商会给你一个目录,比如www,这个www就是你网站的根目录。
2)假设你在www根目录下放了一个文件index.html,这个文件的绝对路径就是: http://www.mf1288.com/index.html。
3)假设你在www根目录下建了一个目录叫tutorials,然后在该目录下放了一个文件index.html,这个文件的绝对路径就是http://www.mf1288.com/tutorials/index.html。
版权所有 © 1992-2012北京市某某高新技术企业有限公司
公司地址:北京市西城区复兴门外大街某某大厦88号
联系电话:010 – 00000000 010 – 00000000 010 – 00000000
国家工业和信息化部网站备案编号:粤ICP备*******号
技术支持:某某科技