Better fix for relative URLs

An improvement to #2711 

cc @koke