Preventing uti from sex?

Is there a way to prevent a uti from sex? I am in a ldr and when my boyfriend came to see me last we had sex a few times. It had been almost a year for me since I had any kind of sex and I ended up with a uti afterwards.

I drink plenty of water, I peed after we finished and took showers/cleaned myself (no soap in vagina). He is also incredibly clean so his hygiene wasnt the issue. The doctor said it sounded like the sex is what caused it although my PH was pretty normal when they did the urine culture.

It was awkward having to pee every 5 seconds the last couple days of his visit and when he comes back in a few months I'd love to avoid that again. I did everything I thought to do and the doctor said it sounded like I had done everything yet I still ended up with one 😭