It's behaving correctly. If you're on http://example.com/index.html
and click a link to two.html
, you end up at http://example.com/two.html
. That's how relative URLs are defined to work.
urljoin
has no way of knowing whether the last component is a directory or not. You could try to guess, perhaps by looking for a .
, and only add the slash if you think it should be there.