News for hackers. Stuff that matters.
Re:Trailing slashes on URLs: Contentious or settled? by neilwilson on Thursday January 27, 2022 @02:32AM (#30097401)
Very much required if you want to use relative URL calculations.

Stumbled across this in Go yesterday

Compare a relativeUrl ref from 'http://localhost/1.0' vs. 'http://localhost/1.0/'

e.g. https://play.golang.com/p/AsUSx6bRWn6

Re:Trailing slashes on URLs: Contentious or settled? by tmpfs on Thursday January 27, 2022 @03:00AM (#30097585)
This is the correct answer. Relative paths are incorrect without a trailing slash.

Use trailing slashes please.

Re:Trailing slashes on URLs: Contentious or settled? by 3np on Thursday January 27, 2022 @03:05AM (#30097616)
Either could be desired behavior and neither is incorrect. If anything, just be consistent within a single site. IMO you're most likely good as long as you consciously pick one, you know why you picked it, and stick with it.
Re:Trailing slashes on URLs: Contentious or settled? by Enderboi on Thursday January 27, 2022 @03:11AM (#30097658)
I literally just closed a ticket about this issue yesterday.. 'why are these relative URLs downloading from the parent folder'.

"Because your CMS is rewriting out trailing slashes. Make it stop that, and then you'll be in the relative path you think your in".

The internet uncertainty principle: It's not DNS, it's trailing slashes. (apologies to Herr Heisenberg :)

Re:Trailing slashes on URLs: Contentious or settled? by hypertele-Xii on Thursday January 27, 2022 @05:26AM (#30098636)
Maybe stop "thinking you're in a path" and actually explicitly define which path you wanna be on [1]. The <base> element has existed expressly for this purpose since 1991, although it was called <address> in the first draft.

[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ba...

Re:Trailing slashes on URLs: Contentious or settled? by jeroenhd on Thursday January 27, 2022 @06:43AM (#30099270)
It depends on your expectations. For example, you could construct a page on https://blog.example.com/my-summer-vacation-2020 and load all resources in the form of static/style.css, static/comments.js, media/header.webp and so on. As long are you're aware of the differences and the way your web server resolves static content, you can pick either, whatever you prefer.

I have no idea what Vercel, Render, and Azure Static Web Apps even are, but you should obviously be aware of their limitations when using them to host HTML. I'm sure there are plenty of other behaviours that differ between them and there's hardly any universal truth to be found in the decisions some big corporations once made.

This article seems more about the default slug-to-content resolution algorithm from a bunch of cloud providers than it is about trailing slashes.

Re:Trailing slashes on URLs: Contentious or settled? by jeroenhd on Thursday January 27, 2022 @06:48AM (#30099321)
I don't get it; that's just how URLs work? This is hardly unexpected behaviour in my opinion. They're not always required, it's a matter of expectation and understanding of how relative URLs work.

You can see /1.0 as a file and /1.0/ as a directory, so the relative URLs make perfect sense either way.

Re:Trailing slashes on URLs: Contentious or settled? by xvector on Thursday January 27, 2022 @03:08AM (#30097637)
Why does .Parse trim the 1.0 when there isn't a trailing slash?
Re:Trailing slashes on URLs: Contentious or settled? by dotancohen on Thursday January 27, 2022 @03:24AM (#30097749)
Because the term "relative" is relative to the current directory, not the current file. It's subtle, but if a directory is being referenced in a form that looks like a file (without the trailing slash) with no additional context, then the parent directory is considered.
Re:Trailing slashes on URLs: Contentious or settled? by dotancohen on Thursday January 27, 2022 @03:22AM (#30097728)
Is that per standard, or the result of an implementation detail in Go that might be different in e.g. Python?
Re:Trailing slashes on URLs: Contentious or settled? by shellac on Thursday January 27, 2022 @04:28AM (#30098201)
Part of the URI standard:

      return a string consisting of the reference's path component
      appended to all but the last segment of the base URI's path (i.e.,
      excluding any characters after the right-most "/" in the base URI
      path, or excluding the entire base URI path if it does not contain
      any "/" characters
https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.3
Re:Trailing slashes on URLs: Contentious or settled? by hn_throwaway_99 on Thursday January 27, 2022 @03:53AM (#30097949)
It's a client-side thing, not a server-side thing. That is, if you have a resource (like an href to another page) in your html, and that link is a relative link, the full URL that your browser ends up requesting depends on whether there is a trailing slash or not, because "relative" is relative to the current URL's directory, and what is considered the current directory differs depending on the presence of a trailing slash.