Pet odors and kids spilled milk are especially nasty odors. The smell is caused by a bacteria/protein that actually eats through fabric and wood. You need something called "uric acid neutralizer" which you can find in vacuum supply stores and hardware stores that rent steam cleaners. Uric acid neutralizer is the active ingredient in all those expensive pet odor sprays. It will reduce the occasional fresh pet or milk accident out of your rug to the point the stench doesn't knock you over, but if your kitty peed there repeatedly (which they often do) or it sank down into the carpet pad and dried you'll probably need to rip out the rug. If it sank into the subfloor, especially if you have that cheap particleboard under your carpets, you'll have to rip out the top layer of subfloor, but if you have plywood or hardwood floors just scrub it down well, hit it with uric acid neutralizer, then once it dries spray it occasionally with plain old rubbing alcohol in a spray bottle to see if that kills the odor (the alcohol could damage the finish on your floors, but it's cheaper than replacing the entire floor). With both kids and pets always having oopsies, we replaced our carpets with hardwood floors and inexpensive area rugs that can just be dragged outside, hosed down, and left to dry in the sun.
Also, try a dehumidifier in that room for a while and see if that reduces the odor. It will help you decide whether it's pet odor or mold (or a combination). If mold is your problem, you're going to have to rip everything out (possibly including sheet rock), scrub the studs and subfloor down with a special mold killer/bleach solution (available at home improvement stores), let it dry thoroughly using a dehumidifier, repeat 2-3x, then redo the room. Mold is both nasty and toxic, causing allergies and asthma attacks. We had a leaky dishwasher hose leak down into a room in the finished basement below and we had to rip out everything down to the wall studs. Nasty stuff.