在question regarding a jQuery Ajax problem中,提问者试图在相对 URL 的开头使用 .
。我建议他把它去掉,但不知道那里的点实际上有什么作用。
他的相对 URL 如下所示:
./delete-misc/test-ajax-code.php
我尝试查看 RFC,但没有成功。我知道点在命令行(Linux 或 Win)中的作用,它代表当前目录。
我想知道:这在 Internet 上的 URL 中是如何工作的?它有任何最佳实践用途吗?欢迎详细解释。
最佳答案
path segment .
通常在相对路径引用的开头使用,并在 reference resolution 期间被删除。 ,即将相对 URI 引用解析为绝对 URI 的过程:
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).
有Remove Dot Segments algorithms它描述了如何在特定的基本路径上下文中解释这些点段。
在您的情况下, ./delete-misc/test-ajax-code.php
和 delete-misc/test-ajax-code.php
是等效的。但在某些情况下,相对路径可能会被误解为绝对 URI,例如在第一个路径段中有一个 :
,例如 search:foo
,它与 ./search:foo
不同,因为前者是绝对 URI,而后者是相对 URI 路径。
关于url - URL 路径中的点是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6008829/