All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
The Islaamic Jurists agree that it is one of the conditions for the validity of the prayer that the person who prays should turn towards the Qiblah (Al-Ka’bah in the sacred mosque in Makkah) except in two circumstances. Firstly, when it is not possible to turn towards the Qiblah because of fear whilst in a battle. Secondly, when a person is performing a supererogatory prayer on the means of transport. There is no difference of opinion amongst the jurists as well that whoever sees the House of Allaah (i.e. Al-Ka'bah) has to turn himself towards it. As regards a person who is not able to see it, he has to face the direction of Al-Ka'bah. This is the view of the majority of the scholars apart from the Shaafi’ee school. The view point of the majority of the scholars is supported by the saying of Allaah (interpretation of meaning): {So turn your face [i.e. yourself] toward al-Masjid al-Haram. And wherever you [believers] are, turn your faces [i.e. yourselves] toward it [in prayer]}[2:144]. It is also supported by the saying of the Prophet : "Between the East and the West is the (direction of) Qiblah." [At-Tirmithi and Ibn Maajah], this is for the residents of Madeenah. As regards the rest of the countries, the direction of Qiblah is also wide, like the distance between the North and the South and so on, because there is difficulty for the people who are far from the Qiblah to exactly face the Ka’bah itself. Allaah says (interpretation of meaning): {He has not laid upon you in religion any hardship.}[22:78]. The evidence about this as well is that all the Muslims agree that the prayer of a very long line in which some people are beyond the direction of the Qiblah is valid. Based on the above grounds, there is no harm to slightly divert from the Qiblah itself as long as you are facing its general direction and you only diverted a slight bit, on the condition that the person praying believed that the Qiblah is in the direction which he faces and that he did not divert from it much.
Allaah knows best.