...How do you prevent the [exhaust] knocking...
Get an exhaust that fits properly?
It's possible that it could just be an assembly error - if one of the sections is slightly rotated, the bends will be all over the
shop.
It could be the exhaust rubbers - being rubber, they can get sloppy over time, but as you've recently had the job done you'd hope that the fitter would have spotted a baggy mount and replaced the offending item(s).
And for the record, not all people's exhausts knock. In 3 exhausts and 120,000 plus miles, I've never noticed any exhaust knocking. Well, apart from when the factory system rotted out at the inlet to the backbox and the backbox swung down...
