我有两个网址:
http://example.com/foo
和
http://example.com/foo/
它们是不同的 URL 还是相同的?同样的问题是关于 FTP 协议(protocol) (ftp://example.com/foo[/])
最佳答案
在URI标准中,相关部分是Normalization and Comparison :
在完成 simple string comparison 之后, 这些 URI 是不等价的。
申请后syntax-based normalization , 这些 URI 是不等价的。
scheme-based normalization ,您必须引用
http
/https
和ftp
URI 方案的规范,并检查是否定义了任何特定于方案的规则:
http
/https
, 这些规则在 http and https URI Normalization and Comparison 部分,而且您的情况似乎没有。ftp
, 似乎没有定义任何规范化/比较规则。
- protocol-based normalization ,您必须考虑重定向之类的东西(在
http
的情况下)。
tl;dr:URI 不相同。
请注意,HTTP(S) URI 中的空路径不是这种情况,如上面链接的部分所定义:
[…] an empty path component is equivalent to an absolute path of "/" […]
所以下面的 URIs 是等价的:
http://example.com/
http://example.com
顺便说一句,对于基于协议(protocol)的规范化,标准以您的案例为例:
[…] For example, if they observe that a URI such as
http://example.com/data
redirects to a URI differing only in the trailing slash
http://example.com/data/
they will likely regard the two as equivalent in the future. […]
关于HTTP/FTP : Does trailing slash in URL mean another resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39717742/