'Ab' is followed by an ablativus and 'ad' is followed by an accusativus.
These prepositions are followed by an accusativus: ad (towards, to, for, at), ante (before), apud (at, by, near, to, towards), inter (among, between), iuxta (next to, near, according to), per (by, through, during), post (after),
And these prepositions are followed by an ablativus: Prepositions + ablative: a (before a consonant) / ab (before a vowel; by, from), coram (in the presence of, before), cum (with), de (from, concerning, of, for), e ((before a consonant) / ex (before a vowel) from, out of), pre (before), pro (for, during, as far as, in accordance with, in return for), sine (without).
See https://www.latin-is-simple.com/en/vocabulary/noun/125/ for the different forms of 'urbs'.
I hope this helps! :)