Firstly, remove 'if' because inversion makes it unnecessary. Then invert the subject and the first verb. So instead of 'I' first and 'had' second, it is 'had' first and 'I' second.
Had I known, I would have taken a different route. Only the sub clause can be inverted; the main clause is not inverted. It stays the same.