The preferable way is not + to + infinitive. But in colloquial speech the negation can be put after "to" to make the whole act of not doing something a positive activity.

An example:

This website is titled "How to not get hit by cars". Getting hit by cars is something you likely want to avoid when riding a bicycle. So you actively do something. Stilistically, it would be better to say "How to avoid getting hit by cars", but that's longer. So the people who created this site opted for "How to not get hit by cars".

If they had called their site "How not to get hit by cars" it would have sounded a little like an explanation of "how to get hit by cars in the proper fashion", avoiding getting hit in the wrong way. Which is clearly not what they intend to teach you.