Etiquette of Visiting the Prophet’s Mosque
Question

If the pilgrim performing Hajj or `Umrah wants to visit the Prophet’s Mosque, should he form the intention of visiting the mosque or of visiting the grave of the Prophet (peace and blessings of Allah be upon him)? And what is the etiquette of visiting the Prophet’s Mosque?
Praise be to Allah.Shaykh Muhammad ibn `Uthaymin (may Allah have mercy on him) said:
Understanding the Purpose of the Visiting the Prophet’s Mosque
“If the pilgrim wants to visit the Prophet’s Mosque before or after Hajj, he should have the intention of visiting the mosque, not the grave, because travelling to a place for the purpose of worship does not include visiting graves, rather it includes only the three mosques: Al-Masjid Al-Haram (the Sacred Mosque in Makkah), Al-Masjid An-Nabawi (the Prophet’s Mosque in Madinah) and Al-Masjid Al-Aqsa (in Jerusalem), as it says in the Hadith which was narrated from the Prophet (peace and blessings of Allah be upon him) who said: “No journey should be undertaken to any mosque except three: Al-Masjid Al-Haram, this mosque of mine and Al-Masjid Al-Aqsa.” (Narrated by Al-Bukhari, 1189 and Muslim, 1397)
Entering the Prophet’s Mosque: The Proper Procedure
When the pilgrim reaches the Prophet’s Mosque, he should enter with his right foot first and say, “Bismillah was-salatu was-salam `ala Rasulillah. Allahumma ighfir li dhunubi waftah li abwab rahmatika. A`udhu Billah il-`adhim wa bi wajhihil-karim wa bi sultanihil-qadim min Ash-shaytan ir-rajim (In the name of Allah, and peace and blessings be upon the Messenger of Allah. O Allah, forgive my sins and open to me the gates of Your mercy. I seek refuge in Allah the Almighty and in His noble Face and in His ancient Power, from the accursed devil).” Then he should pray as he likes.
Praying in Ar-Rawdah: A Special Virtue
It is better for him to pray in Ar-Rawdah which is the area between the pulpit of the Prophet (peace and blessings of Allah be upon him) and the room in which is his grave, because this area is one of the gardens (Riyad, sing. Rawdah) of Paradise.
Etiquette of Visiting the Prophet’s Grave
When he has prayed and wants to visit the grave of the Prophet (peace and blessings of Allah be upon him), he should stand in front of it in a dignified manner and say, “As-salamu `alayka ayyuhan-Nabiyyu wa rahmat-Allahi wa barakatuhu. Allahumma salli `ala Muhammad wa `ala ali Muhammad kama salayta `ala Ibrahim wa `ala ali Ibrahim, innaka hamidun majid; Allahumma barik `ala Muhammad wa `ala ali Muhammad  kama barakta `ala Ibrahim wa `ala ali Ibrahim, innaka hamidun majid. Ashhadu annaka Rasul-Allah haqqan wa annaka qad balaghta Ar-risalah wa adayta Al-amanah wa nasahta Al-ummah wa jahadta fillahi haqqa jihadihi. Fa jazaka Allahu `an ummatika afdal ma jaza nabiyyan `an ummatihi.
(Peace be upon you, O Prophet, and the mercy of Allah, and His blessings. O Allah, send prayers upon Muhammad and upon the family of Muhammad, as You sent prayers upon Ibrahim and the family of Ibrahim, verily You are Worthy of Praise, Full of Glory. O Allah, send blessings upon Muhammad and upon the family of Muhammad, as You sent blessings upon Ibrahim and the family of Ibrahim, verily You are Worthy of Praise, Full of Glory. I bear witness that you are indeed the Messenger of Allah, that you conveyed the message and fulfilled the trust, and advised the Ummah and strove truly for the sake of Allah. May Allah reward you on behalf of your Ummah better than any Prophet is rewarded on behalf of his nation).”
Visiting the Companions’ Graves
Then he should move a little to his right and send Salams upon Abu Bakr As-Siddiq and pray that Allah be pleased with him.
Then he should move a little further to his right and send Salams upon `Umar ibn Al-Khattab and pray that Allah be pleased with him. If he makes Du`a for Abu Bakr and `Umar (may Allah be pleased with them) in an appropriate manner, that is good.
It is not permissible for anyone to seek to draw closer to Allah by touching the room of the Prophet (peace and blessings of Allah be upon him) or by circumambulating it, or by facing it whilst making Du`a. Rather he should turn to face the Qiblah, because drawing closer to Allah can only be done by means of that which Allah and His Messenger have prescribed. Acts of worship are based on following not on innovation.
Etiquette for Women Visiting the Prophet’s Mosque
Women should not visit the grave of the Prophet (peace and blessings of Allah be upon him) or any other grave, because the Prophet (peace and blessings of Allah be upon him) cursed women who visit graves. (Narrated by At-Tirmidhi and classed as sound by Al-Albani in Sahih At-Tirmidhi, 843)
Rather a woman should pray and send blessings upon the Prophet (peace and blessings of Allah be upon him) in the place where she is, and that will reach the Prophet (peace and blessings of Allah be upon him) no matter where she is.
The Prophet (peace and blessings of Allah be upon him) said: “Send blessings upon me, for your blessings will reach me no matter where you are.” And he said, “Allah has angels who travel about throughout the land, conveying to me the Salams of my Ummah.” (Narrated by An-Nasa’i, 1282; classed as authentic by Al-Albani in Sahih An-Nasa’i, 1215)
Visiting Other Holy Sites
Only men should visit Al-Baqi`, which is the graveyard of Madinah. They should say: “As-Salamu `alaykum ahl Ad-diyar min Al-mu’minin wal-muslimin, wa inna in sha Allah bikum lahiqun. Yarham Allah Al-mustaqdimina mina wa minkum wal-musta’khirin. Nas’al Allah lana wa lakum Al-`afiyah. Allahumma la tahrimna ajrahum wa la taftinna ba`dahum waghfir lana wa lahum.
(Peace be upon you, O dwellers of these abodes, believers and Muslims. We will, when Allah wills, join you. May Allah have mercy on those who were first (to die) and those who were last. We ask Allah to grant salvation to us and you. O Allah, deprive us not of reward (similar to theirs) and lead us not astray after they are gone; forgive us and them).”
If the pilgrim then wants to go to Mount Uhud and remember what happened there to the Prophet (peace and blessings of Allah be upon him) and his companions in that battle of Jihad, trials and martyrdom, and send Salams upon the martyrs there, such as Hamzah ibn `Abd Al-Muttalib (may Allah be pleased with him), the paternal uncle of the Prophet (peace and blessings of Allah be upon him), there is nothing wrong with that, because that is a kind of travelling through the land as enjoined (in Islam) [cf. An-Nahl 16:36].” (End quote from Al-Manhaj li Murid Al-`Umrah wal-Hajj)
For more details, please see the following answers: 36647, 34752, 115693, 21960.
And Allah knows best.