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 - a is less frequently utilized than ab before consonants.