Additional checks in unresolved routing handler

Performs some additional checks on the existing path and query string
before using them in any redirect logic -- just in case.