We had this problem several times, and it's more worrying than I would have thought. (Are there any cases of exploding babies on record? I don't think so.)
The gentle, longer term answer is apple juice and apple sauce, according to my son's pediatrician. And we used that, but it's so gentle you never know for sure that it worked. Ask your pediatrician how much to give (and whether he/she approves).
When you get desperate (and consult your pediatrician first!) there are glycerin suppositories. My son's pediatrician had us use these little tubes of glycerin. It's supposed to work after some period of time, but each time we used it, the reaction was immediate -- a horrifying mess, but lots of relief for my son. All I can say is, have lots of paper towels nearby.
Also, my son seems to have grown out of the problem.
Good luck!