整合营销
相对路径和绝对路径区分
2012-03-29
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。