Urinary Tract Infection/ STD

I think I may have a unrinary tract infection. I have had them before but i just recently got one and I am just wondering how they are caused and how I can prevent them. Does getting fingered and having sex cause them? Also, about std/sti, if you and your partner both aren't infected, could you guys become infected? That may sound stupid but I just want to be 100% sure because it had to have started somehow. Thanks!