The key is to keep bacteria out of your system. 1  Drink plenty of water, and relieve yourself often. The simplest way to prevent a UTI is to flush bacteria out of the bladder and urinary tract before it can set in. 2  Wipe from front to back. Bacteria tend to hang around the anus. 3  Wash up before sex and urinate after it. Use soap and water before sex.