Your medical professional will chose the optimal medication for your condition. If it is an infection, will be prescribed and you should take the full course of the medication, even if you feel better.
Urinating at bedtime and after sexual intercourse, not holding urine for an excessive amount of time, and good hygiene can decrease the chances of developing a urinary tract infection. Of note, these are only helpful hints as they will not guarantee prevention. Avoid any irritating product on the outside of your genitals if you are experiencing dysuria.
Any patient experiencing symptoms of dysuria should seek medical attention.