Take query into account when validating external links

This is a fix for #279.