There are no “rules” for preventing it, as it happens somewhat at random, I have the following advice that might help you.
1) Drink at least 4 liters of water a day. Try to stick to a rule of 2 liters before lunch and 2ltr after before you go to bed. which will work wonderfully.
2) Go slow. Slow walking will help us get used to the altitude substantially. There is no point blasting up the trail because once you get to the lodge you’re not doing anything the rest of the day most of the time. Pace yourself, be sure to get in before the sun goes behind the mountain, and enjoy the scenery.
The second your heart rate rises from too much exertion, stop and recover.
3) Acclimatization days are important, get use to with that elevation first before you go higher elevation. Go higher and sleep lower on acclimatization day, same time you will be enjoying your day with beautiful views.
4) Diamox. There are some who believe Diamox only masks the symptoms of altitude sickness, while others who argue that it helps.
I can’t promise you that this will make sure you do not get AMS, but I can say it certainly doesn’t hurt.