Facing the qiblah is one of the conditions of prayer being valid, because Allaah says (interpretation of the meaning):
“Verily, We have seen the turning of your (Muhammad’s) face towards the heaven. Surely, We shall turn you to a Qiblah (prayer direction) that shall please you, so turn your face in the direction of Al-Masjid Al-Haraam (at Makkah). And wheresoever you people are, turn your faces (in prayer) in that direction”
The one who is close to the Ka’bah is required to face it head on, but the one who is far away from it must face its direction, according to the majority of scholars.
Ibn Qudaamah (may Allaah have mercy on him) said in al-Mughni: Facing the qiblah is a condition of prayer being valid, and there is no difference between obligatory and naafil prayers in this regard.
The one who is far away from Makkah must seek the direction of the Ka’bah, without having to face it head on.
Ahmad said: Whatever is between the east and the west is qiblah, and a small deviation from the qiblah does not matter, but he has to try to get it right as much as possible. This was also the view of Abu Haneefah. This view is based on the hadeeth in which the Prophet (peace and blessings of Allaah be upon him) said: “Whatever is between the east and the west is qiblah.” Narrated by al-Tirmidhi. End quote.
From the words of Imam Ahmad quoted above we learn two things:
One has to do with your past prayers, which are valid and you are not required to repeat them.
The other has to do with your future prayers; you have to correct the rows and you should not deliberately deviate from the qiblah.
This is the view of the majority of scholars. Imam al-Shaafa’i (may Allaah have mercy on him) was of the view that it is essential to face the Ka’bah head on even for the one who is far away, and prayer is invalidated in his view if there is a deviation of this type from the qiblah.
See also al-Majmoo’ (3/208).
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) said: Facing the qiblah means either facing the qiblah head on or facing its direction. If a person is close to the Ka’bah and can see it, then he must face the Ka’bah head on, because this is basic principle. But if he is far away and cannot see the Ka’bah, then he must face its direction. The further away a person is from Makkah, the more flexible the direction is for him, because the larger a circle grows, the more leeway there is, hence the Prophet (peace and blessings of Allaah be upon him) said: “Whatever is between the east and the west is qiblah.” That was with regard to the people of Madeenah, and the scholars stated that a slight deviation in the qiblah does not matter.
The well known directions are four: north, south, east and west. If a person is east or west of the Ka’bah, then the qiblah for him is between north and south. If he is north or south of the Ka’bah, then the qiblah for him is between the east and the west, because what is required is to face that direction. End quote from Fiqh al-‘Ibaadaat, p. 154.
There is nothing wrong with putting a line etc so that the row will be facing the proper direction of the qiblah. This is better than praying in a direction that deviates from the right direction.
It is better for a person to pray in the mosque in his own neighbourhood or near his house, and he should not go further away to another mosque except for a shar’i reason. It is hoped that those who are in charge of the mosque will correct the direction of the rows and not deviate from the qiblah to the right or left, so as to be on the safe side with regard to prayer, because some of the imams regard the prayer as invalid if there is such deviation, as we have stated above.
May Allaah help us all to do that which He loves and which pleases Him, and may He unite you in righteousness and piety.
And Allaah knows best.