it's a stupid rule, really the phonetics are more or less identical to german, "ie" is like the slavic iy, rising tone like english EE and ei is like - well, like the old vulgar latin like the word "eye" such as your native language portuguese, except when it's french and then it's back to front like counterfeit which sounds like counter-feet
and then there is the ai dipthong which is also french but also german and has different sounds depending on the word, as also the reverse is usually spoken with an intervening schwa like the russian e and я
that's why english is such a fucked up language, way more exceptions to rules than almost any other language, it's a blend of german, french, latin, greek, irish, welsh and scottish