Is there a specific character that can be used in a URL where any text after that character would be ignored by the browser?
For example: if tilde would a character like that and I have a link (with a comment added) like www.stackoverflow.com/~aComment, it would just ignore 'aComment' and open www.stackoverflow.com/. But as tilde isn't the comment-character, it now just shows a 'page not found'-page.
In other words, how to add a comment to a url without breaking it?
There is no such thing for URL's. There are things you can add to the URL that will work often, but there is no way that will be guaranteed to work for every URL.
Two options that I can think of that you might have the most success with:
Everything after a #
in the URL will not be sent to the server. It can be used to point to a part of the page. It can also be queried by JavaScript, so it might cause issues if the JavaScript sees something it is not expecting.
Example:
https://www.example.com/path#comment
The query string us used to add specific details to a URL that is specific to the path. This part is sent to the server. Most servers will ignore query strings they don't recognize, but this is not guaranteed. Servers might throw errors or have other unexpected behavior upon finding query string parameters they don't expect.
Example:
https://www.example.com/path?comment=value
Or when there is more than one query string parameter:
https://www.example.com/path?param1=value1&comment=value
You can use both to the URL of this very question to see them working. Clicking this link will show you that the question will load fine.
Of course, since you are working with URL's, all values added to them should be properly encoded so they don't break the syntax.