Get Pet Smells Out of Carpet

How do you get pet urine out of your carpet and stop the odor so the dog does not go back to same area.