That's actually not a rule. ab and ex can lose their consonant, but in fact it's far more common for them not to. Check out Lewis and Short's entries on them:
ex/e
ex always before vowels, and elsewhere more frequent than e; e. g. in Cic. Rep. e occurs 19 times, but ex 61 times, before consonants—but no rule can be given for the usage; cf., e.g., ex and e together: “qui ex corporum vinculis tamquam e carcere evolaverunt,” Cic. Rep. 6, 14. But certain expressions have almost constantly the same form, as ex parte, ex sententia, ex senatus consulto, ex lege, ex tempore, etc.; but e regione, e re nata, e vestigio, e medio, and e republica used adverbially.
ab/a is more complicated, but you even see archaicisms like abs te very frequently. Same thing applies, though: a is used less often than ab before consonants. Nathaniel in another thread posted the relevant part of Lewis and Short concerning when you use ab and a:
[ab] has become the principal form and the one most generally used through all periods—and indeed the only one used before all vowels and h; here and there also before some consonants, particularly l, n, r, and s; rarely before c, j, d, t; and almost never before the labials p, b, f, v, or before m.
Worth reading other posts in that thread, too.