In American English, the one-word version is the only version for the adverb meaning continually, incessantly, or eternally.
Traditionally in British English the one-word version means continually or persistently and the two-word means eternally. This however is not the case anymore and the American English standard mentioned above is now being used for the British version.
The two-word version, according to OED citations, is by far the oldest, first showing up around 1300 in Cursor Mundi, a Middle English poem: “This folk … that suld vs serue for euer and ai” (“This folk … that should us serve for ever and always”).
I do write "for ever" sometimes, and the only rule I could come up with was, if you can substitute "always," you should use the one-word version of forever. But two words sometimes looks better when your meaning is "for good."