It is narrated from Sayyiduna Ibn Abbas (may Allah be pleased with them both) that the Prophet (peace and blessings be upon him) used to pray (in Makkah) facing Bayt al-Maqdis, keeping the Ka'bah between himself and Bayt al-Maqdis. After that, when he (migrated and) came to Madinah, he kept praying facing Bayt al-Maqdis for sixteen months. Then Allah turned him towards the Ka'bah.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2193