Facing the qiblah or turning one’s back to it in an open area when reliving oneself is prohibited. However, if the toilet is in a building or there is a screen between the person using it and the qiblah, one may use it.

Facing the qiblah when relieving oneself

If a person is relieving oneself in an open area, as in the desert, one may not face the qiblah or turn one’s back to it. 

:Abu Ayyub al-Ansari quotes the Prophet (peace be upon him) as saying

 ‘When you go to the toilet, do not face the qiblah and do not turn your back to it, but face the east or the west.’  

 Abu Ayyub adds:

‘When we travelled to Syria, we found toilets that were built towards the direction of the Ka'bah. Therefore, we used them sideways and prayed for forgiveness.’

If the toilet is within a building, or when there is a screen between the person using it and the qiblah, one may use it.

: 'Abdullah ibn 'Umar reports

‘I went over Hafsah’s roof for something I needed. I went over Hafsah’s roof for something I needed.I overlooked the Prophet (peace be upon him) sitting for his toilet with his back towards the qiblah and facing Syria.’  

Related by al-Bukhari, hadith No. 148, Muslim, hadith  No. 266

:Marwan reports

‘I saw 'Abdullah ibn 'Umar when he sat his camel facing the qiblah, and then he sat to urinate. I said to him: “Abu 'Abd al-Rahman, is not this way prohibited?” He said: “Yes, when in an open area; but when there is something to screen you from the qiblah, then there is no harm.’ 

Related by Abu Dawud, hadith No. 11; al-Daraqutni, hadith No. 161; al-Hakim, vol. 1, p. 256

However, it is more preferable not to face the qiblah when in the toilet, even in buildings.