Smarter relative URL replacing