If your dog goes to the bathroom indoors, and you don't catch them in the act, don't bother to punish them. They won't associate the punishment with something they did minutes or hours before. Simply clean up the mess and resolve to be more careful in the future. If you carefully supervise your dog and crate them when you are not able to, they won't have the chance to have an accident. If at all possible, maintain a 100% success rate by very careful supervision and crating. Every time that your dog gets to relieve themselves indoors, they are getting a reward (relief) for going to the bathroom indoors, and you set back your housetraining efforts greatly. If you maintain this procedure rigorously, you won't have to keep up your vigilence for very long (for an adult dog, you'll be well on your way within 24 hours). Soon your dog will be holding it in until their next scheduled potty break, and you'll have only yourself to blame if you forget to go for the potty break on time.
If you do catch your dog in the act, you have more of a learning opportunity. Make a noise or something else sufficient enough to get them to stop temporarily. Then take them to their potty spot immediately. If they go to the bathroom while outside, reward them! They're now doing what you want, and they will associate the praise or treat with what they are doing as they get the reward (that is, going to the bathroom outside), not with what they did indoors. Don't try to punish the dog - in the worst case they'll just learn to go to the bathroom when you aren't around, which isn't the desired lesson. Instead of punishment, focus on getting them outside where they can perform the behavior that you want instead.
When cleaning up dog urine, make sure to use one of the enzyme based cleaners that you get at a pet store. If the urine smell lingers, it may encourage your dog to use that spot again. Even for feces, it is good to apply a spot of the cleaner (your dog's nose is much more sensitive than yours).