Masjid al-Rayah is one of the old mosques in Madinah. It is located on top of a hill called Jabal Dhubab, also known as Jabal al-Rayah, and the mosque is named after it.
This is the place where the Prophet Muhammad (peace be upon him) set up a tent during the Battle of the Trench (Ghazwat al-Ahzab) to watch over the digging of the trench for protecting the city.
The mosque was first built during the time of Omar ibn Abd al-Aziz, the governor of Madinah from 87–93 AH (706–712 CE). It was built right where the Prophet (peace be upon him) stood to supervise the work.
Recently, the mosque was renovated during the time of King Salman bin Abdulaziz Al Saud.