URL 路径中的点是什么意思?
在有关 jQuery Ajax 问题的问题中,提问者试图在相对 URL 的开头使用 .
。我建议他把它去掉,但不知道那里的点实际上有什么作用。
他的相对 URL 如下所示:
./delete-misc/test-ajax-code.php
我尝试查找 RFC,但没有成功。我知道点在命令行(Linux 或 Win)中的作用,它代表当前目录。
我想知道:这在互联网上的 URL 中是如何工作的?它有任何最佳实践用途吗?非常欢迎详细的解释。
In a question regarding a jQuery Ajax problem, the asker was trying to use a .
in the beginning of a relative URL. I advised him to remove it, but have no idea what a dot actually does there.
His relative URL looked like this:
./delete-misc/test-ajax-code.php
I tried looking in the RFCs, without success. I know what the dot does in command line (either Linux or Win), it represents the current directory.
I'd like to know: how does this work on the Internet in a URL? Does it have any best-practice uses? Detailed explanations are most welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常使用 路径段
.
在相对路径引用的开头,并在 引用解析,即将相对URI引用解析为绝对URI的过程:有删除点段算法 描述了如何在特定的基本路径上下文中解释这些点段。
在您的情况下,
./delete-misc/test-ajax-code.php
和delete-misc/test-ajax-code.php
是等效的。但在某些情况下,相对路径可能会被误解为绝对 URI,例如,第一个路径段中的:
与search:foo
不同。 ./search:foo 因为前者是绝对 URI,而后者是相对 URI 路径。The path segment
.
is typically used at the begin of relative path references and are removed during the reference resolution, i.e. the process of resolving a relative URI reference to an absolute URI:There is Remove Dot Segments algorithms that describes how these dot segments are to be interpreted in a certain base path context.
In your case both
./delete-misc/test-ajax-code.php
anddelete-misc/test-ajax-code.php
are equivalent. But there are cases where a relative path can be misinterpreted as an absolute URI, e.g. having a:
in the first path segment likesearch:foo
that is different to./search:foo
as the former is an absolute URI while the latter is a relative URI path.URL 前面的
./
相当于当前路径。所以./delete-misc/test-ajax-code.php
和delete-misc/text-ajax-code.php
都是相对路径。在您发布的答案中,您要求仅删除点,因此/delete-misc/test-ajax-code.php
的路径将转换为绝对路径而不是相对路径。编辑:还有一件事 -
.
是当前目录,..
是父目录。正如 phihag 评论的那样,这些确实应该在代码中避免和保护。目录遍历可用于作恶。A
./
in front of the URL is equivalent to the current path. So./delete-misc/test-ajax-code.php
anddelete-misc/text-ajax-code.php
are both relative paths. In the answer you posted, you asked to remove the dot only, so the path of/delete-misc/test-ajax-code.php
would translate as an absolute path instead of a relative path.Edit: one more thing -
.
is the current directory and..
is the parent directory. As phihag comments, these really should be avoided and protected against in code. Directory traversal can be used for evil.现在进行更简单的解释...
.
和..
并不等效!./
和../
不相等!.
和./
ARE 等同于在所有情况下,
.
和./
与或“”相同,或者没有路径,因此不需要或在 Web 上使用。
.
(点)是旧 UNIX 路径系统的遗物,不用于万维网上创建路径!为什么?因为路径中的点是多余的,相当于“”或无路径
或当前所在的文件目录。相同的结果适用于使用./< /代码>。它与“”或
无路径
相同。两者都只是引用文件所在的本地目录(“./webpage.html”=“webpage.html”)。我应该使用什么路径?
.
或./
,因为这两个路径是不相关的!../
这是一个相对路径,表示向上一个文件夹。/
这是绝对路径,表示从网站根文件夹开始。想要更多证据?
查看这些图像路径的结果。假设您从存储在网站根目录中的 HTML 网页引用这些路径:
Now for a Simpler Explanation...
.
and..
are NOT equivalent!./
and../
are NOT equivalent!.
and./
ARE equivalent toIn all cases,
.
and./
are the same asor "" or no path so not needed or used on the Web.
.
(dot) is a relic of old UNIX pathing systems and NOT used on the World Wide Web for creating paths! Why? Because the dot in paths is redundant and equivalent to "" orno path
or the current file directory you are in. The same result applies to using./
. It is the same as "" orno path
. Both just reference the local directory your file is in ("./webpage.html" = "webpage.html").What Path Should I Use?
.
or./
as both paths are irrelevant!../
which is a RELATIVE PATH and says go up one folder./
which is an ABSOLUTE PATH and says starts from the website root folder.Want More Proof?
Check out the result for these image paths. Assume you are referencing these paths from an HTML web page stored in the root of the web site: