I haven’t run into this solecism lately, but I ran into the lesson on Facebook. Here it is:
The noun phrase “a while” can and often does follow a preposition, such as “for” or “in.” The adverb “awhile” cannot follow a preposition.
If you can replace “a while” with another article and noun such as “a year,” you know you want the two-word version. If you can replace “awhile” with another adverb such as “briefly,” you know you want the one-word version.