There are a lot of things you can do to try to keep them from coming back. As with urinary tract infections and bacterial vaginosis, the following things can help.
Do not wear underwear with colored fabric in the crotch (for lack of better term.)
do not take baths, only showers
do not use colored toilet paper or scented tampons
cut out caffiene
if you are sexually active, have him wear condoms (preferably not lubricated) this may sound strange, but bacteria on the penis can get inside you so very easily and cause an infection, also, and this is even more weird, cum can grow bacteria inside of you and also cause an infection. This also goes for "fingering" make sure his hands are clean!
That is all I can think of right now. But a lot of people still get them even if they do all of the above. But a lot of doctors will give you refills on the oral prescription, so that when symptoms start to come back you can just get the pills and get rid of the infection.
Hope this helps!