The first one is performing voluntary prayers while riding (an animal, car and so on). The rider may bend his head slightly for the bowings and prostrations of the prayer, but he should bend a little bit lower for the prostrations. He may face in whatever direction his ride is going.
Reported ‘Amr ibn Rabi’ah, “I saw the Messenger of Allah, upon whom be peace, pray while riding, and he faced the direction in which he was going.” This hadith is related by Muslim, at-Tirmizhi and al-Bukhari. The latter added that “he bent his head slightly.”
He did not, however, do this for the obligatory prayers. Ahmad, Muslim and at-Tirmizhi recorded that he would pray on his mount while travelling from Makkah to Madinah, facing away from Makkah. Upon this, Allah revealed, “Wherever you turn, you will find Allah’s face.” Says Ibrahim an-Nakha’i, “They would pray on their mounts and animals in the direction in which they were facing.” Ibn Hazm comments, “This has been related from the companions and those of the following generation, during travel and residence. “
The second case is praying while having to deal with forced conditions, illness and fear. Under such circumstances, it is allowed to pray without facing the qiblah. The Prophet, upon whom be peace, said, “If I order you to do something, do what you are capable of doing.” Says Allah, “If you go in fear, then (pray) standing or on your mounts…” (al-Baqarah 239). Ibn ‘Umar added, “Facing the qiblah or not facing it.” (Related by al-Bukhari.)