Let's approach this subject with candor, because, hey, although what we're about to talk about isn't funny when it's happening to you in Mexico, it can be funny afterward, and makes for some great stories later.
So, what's up with Montezumas Revenge? Montezuma's Revenge is a slight sickness that many tourists to Mexico halfheartedly joke about. At times it can become a more severe sickness, especially in the case of infants and children. It's named after the ruler of the Aztecs, Moctezuma II, who was eventually defeated by Cortes. The joke then goes that Montezuma is getting revenge on the guëros (Americans) by cursing them with diarrhea, possibly vomiting and general upset stomach.
In reality, traveler's diarrhea is caused by bacteria or other toxins in the water. A lot of water has bacteria in it, even here in the U.S.(So don't swim with your mouth open, because apparently Montezuma makes it up this way too!)
Sometimes traveler's diarrhea is caused by straight up bad water, and sometimes the issue is more of a function of the kinds and types of flora that populate one's gut. You have a delicate balance of bacteria in your gut, and introducing different flora into your system (no matter their nationality) can put you out of balance, no e. coli required.
So, how to avoid this particular issue on your vacation? Well, as the advice goes, you'll need to avoid water that hasn't been filtered. You'll need to avoid drinking it, brushing your teeth with it, eating foods washed with it, or drinking it as ice in your soda.
This is actually very difficult once you've been in Mexico for a while: food vendors peddle juicy, fresh pineapple, icee stands are set up in the middle of the hot plazas, and it's hard to remember to ask for filtered ice in your margarita after you've already had two or three. Luckily many restaurants, especially in tourist and resort areas, automatically use filtered agua, so this may not be a problem based on where you visit.
In my personal travels, I've not made this a priority, and haven't really regretted it. On the other hand, I haven't exactly chugged water from the tap, either. Often my travels begin with caution, but after a couple days in the country, it gets tiresome. I don't generally visit tourist areas, so this can require a lot more vigilance than I am ready to give on my vacation. Luckily, I've had very minor issues, if any.
For those who are a little more cautious, you'll be happy to know that finding filtered water is quite easy. You may also want to consider preparing your gut ahead of time by eating probiotic yogurts.