文件Uri计划和相关文件

假设uri的scheme是“文件”。 还假定path以'。'开头。

示例path是“./.bashrc”。 fulluri怎么样? 'file://./.bashrc'对我来说显得很奇怪。

简而言之,文件URL的forms是:

 file://localhost/absolute/path/to/file [ok] 

或者你可以省略主机(而不是斜杠):

 file:///absolute/path/to/file [ok] 

但不是这样的:

 file://file_at_current_dir [no way] 

也没有这个:

 file://./file_at_current_dir [no way] 

我刚刚证实,通过Python的urllib2.urlopen()

来自http://en.wikipedia.org/wiki/File_URI_scheme的更多详情:;

 "file:///foo.txt" is okay, while "file://foo.txt" is not, although some interpreters manage to handle the latter 

用'。'来使用完整文件:URI是不可能的。 或“..”分段的path没有该path的根部分。 无论你使用'file://./.bashrc'还是'file:///./.bashrc',这些path都没有意义。 如果您想使用相对链接,请在没有协议/权限部分的情况下使用它:

 <a href="./.bashrc">link</a> 

如果你想使用完整的URI,你必须告诉一个根相对你的相对path是:

 <a href="file:///home/kindrik/./.bashrc">link</a> 

根据RFC 3986

 The path segments "." and "..", also known as dot-segments, are defined for relative reference within the path name hierarchy. They are intended for use at the beginning of a relative-path reference (Section 4.2) to indicate relative position within the hierarchical tree of names. This is similar to their role within some operating systems' file directory structures to indicate the current directory and parent directory, respectively. However, unlike in a file system, these dot-segments are only interpreted within the URI path hierarchy and are removed as part of the resolution process (Section 5.2). The complete path segments "." and ".." are intended only for use within relative references (Section 4.1) and are removed as part of the reference resolution process (Section 5.2). However, some deployed implementations incorrectly assume that reference resolution is not necessary when the reference is already a URI and thus fail to remove dot-segments when they occur in non-relative paths. URI normalizers should remove dot-segments by applying the remove_dot_segments algorithm to the path, as described in Section 5.2.4. The complete path segments "." and ".." are intended only for use within relative references (Section 4.1) and are removed as part of the reference resolution process (Section 5.2) 

RFC 3986甚至描述了删除这些“。”的algorithm。 和“..”来自URI。

在terminal中,您可以使用“$ PWD”键入“file://$PWD/.bashrc”来引用当前目录。