As far as 'avoiding' it is concerned, your stomach is being pushed out of position and there is nothing to do to change that, short of having the baby. Some women simply do get extreme heartburn from this involuntary repositioning of their internal arrangement, others (the lucky ones) don't.
As as far as treating the symptom, ask your ob-gyn for a list of approved heartburn meds (don't take just anything, ask your doc or your pharmacist).