Prevention is always the best alternative to pet odors. However, it is not always possible. Prevention of odors consists of: vacuuming regularly to keep odors from setting in; using carpet sealant to protect the carpet before a pet has an accident.
Accidents still may happen. It is important to deal with the accidents immediately blotting the urine out of the carpet and using a mild dish soap with water remove as much of the pet accident as possible. You can sprinkle carpet deodorant or baking soda on the spot allow it to sit and soak up the odor and then vacuum.
The secret to removing the rest of the odor out of the carpet is to then coat the accident area with live enzyme digester/deodorant cleaner (I’ve used Enzym D Digester Deoderant). Enzyme digesters are pretty expensive, however the liquid is concentrated and is mixed with water before spraying on the spot where the odor is coming from. The spot needs to be soaked with the enzyme mixture for the enzymes to work.
If the spot is older and you cannot find where the odor is coming from, one solution is to purchase a black light (hotels use black lights to inspect rooms often). The black light in a very dark room will show up any protein stains. You may find more stains than you bargained for. Odors may also be on the wall and in the furnature, the black light will show possible sources of the odor.
If you have a room air cleaner make sure it is clean and functional and have it running. In the hotel industry we sometimes use Ozone machines. When using ozone machines to remove odors from the air it is important to be sure to never, never, never be in a room with an ozone machine that is running, and try to stay away for at least an hour or longer after it has finished. It is important to also make sure that there are no animals in the room with the ozone machine when it is running. They are effective at freshening the air and work on cigarette smells as well. But ozone can damage the lung tissues if you are in the room while it is running.