Fix/cdodge/bad links can cause exception on rewrite

@cahrens I regenerated the PR as the previous one had some commits not part of this branch.