JimJim2000 JimJim2000 - 2 months ago 9
HTTP Question

HTTP/FTP: Does trailing slash in URL mean another resource

I have two URLs:

http://example.com/foo


and

http://example.com/foo/


Are they different URLs or the same? The same question is and about FTP protocol
(ftp://example.com/foo[/])

Answer

In the URI standard, the relevant section is Normalization and Comparison:

  1. After doing a simple string comparison, these URIs are not equivalent.

  2. After applying syntax-based normalization, these URIs are not equivalent.

  3. For scheme-based normalization, you have to refer to the specifications of the http/https and ftp URI schemes, and check if any scheme-specific rules are defined:

  4. For protocol-based normalization, you have to take something like redirects into account (in case of http).

tl;dr: The URIs are not equivalent.


Note that this is not the case for an empty path in HTTP(S) URIs, as the section linked above defines:

[…] an empty path component is equivalent to an absolute path of "/" […]

So the following URIs are equivalent:

http://example.com/

http://example.com

By the way, for the protocol-based normalization, the standard gives your case as an example:

[…] 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. […]