Urinary tract infections (UTIs) are a major public health problem affecting millions of individuals each year. Recurrent UTIs are managed by long-term antibiotic use, making the alarming rise of antibiotic resistance a substantial threat to future UTI treatment. Extended antibiotic regimens may also have adverse effects on the microbiome. Here, we report the use of a supramolecular vaccine to provide long-term protection against uropathogenic Escherichia coli, which cause 80% of uncomplicated UTIs. We designed mucus-penetrating peptide-polymer nanofibers to enable sublingual (under the tongue) vaccine delivery and elicit antibody responses systemically and in the urogenital tract. In a mouse model of UTI, we demonstrate equivalent efficacy to high-dose oral antibiotics but with significantly less perturbation of the gut microbiome. We also formulate our vaccine as a rapid-dissolving sublingual tablet that raises response in mice and rabbits. Our approach represents a promising alternative to antibiotics for the treatment and prevention of UTIs.