Rainbows, halos, sun dogs, light pillars and other so-called optical illusions are just that: illusions. They are not actually there. You can never get to the end of the rainbow. You cannot see light pillars from an airplane. You cannot see a sun dog from the other side. All of these optical phenomena are merely light which has been bent and sometimes refracted so that you seem to be seeing an object in the sky. In fact, what you see is not actually there.
Because the light is getting bent before it reaches your eyes, you are seeing the light from the direction of its last bend. Ice crystals or raindrops are located in the place the illusion appears to be, and are bending light coming from somewhere else. The shapes of the ice crystals or rain drops are responsible for the deflection, refraction, or both.