It comes from German pronounciation, which has much stricter rules AFAIK. ei is pronounced i, ie is pronounced e. Thus the english rule, I before E when the sound is "ee".
Exceptions are generally, from Latin or French words where the sound is "a", or "i", or "uh" or.. etc. These are often...