Ruling on travelling to visit the grave of the Prophet (peace and blessings of Allaah be upon him)
Question

                What is the ruling on travelling to visit the grave of the Prophet (peace and blessings of Allaah be upon him) and others graves of awliya’ and righteous people and others?
Praise be to Allah.It is not permissible to travel with the intention of visiting 
          the grave of the Prophet  (peace 
          and blessings of Allaah be upon him) or the grave of any other person, 
          according to the more correct of the two scholarly opinions, because 
          the Prophet  (peace and blessings 
          of Allaah be upon him) said: 
“No one should travel for the purpose of visiting (any mosque) except 
          three: al-Masjid al-Haraam (in Makkah), this mosque of mine (in Madeenah) 
          and al-Masjid al-Aqsaa (in al-Quds/Jerusalem).” Agreed upon).  
          
It is prescribed for the one who wants to visit the grave 
          of the Prophet  (peace and blessings 
          of Allaah be upon him) and who lives far from Madeenah to have the intention 
          of travelling to visit al-Masjid al-Nabawi; that will include by implication 
          visiting the grave of the Prophet  
          (peace and blessings of Allaah be upon him), the graves of Abu Bakr 
          and ‘Umar, and the graves of the martyrs and people of al-Baqee’. 
If he has the intention of visiting both (the mosque and 
          the grave), this is permissible, because things may be permissible as 
          part of something else which are not permissible on their own. But having 
          the intention only to visit the grave and travelling for that purpose 
          is not permissible. Intending to visit the grave only is not permissible 
          if it involves travelling. But if a person lives close by and does not 
          need to travel, and his going to the grave is not regarded as “travel” 
          or a “journey”, then it is OK, because visiting the grave of the Prophet 
           (peace and blessings of Allaah 
          be upon him) and the graves of his two companions without having to 
          travel is Sunnah and is an act of worship. The same applies to visiting 
          the graves of the martyrs and of the people of al-Baqee’. Similarly, 
          visiting the graves of Muslims in all places is Sunnah and is an act 
          of worship, but without travelling for that purpose, because the Prophet 
           (peace and blessings of Allaah 
          be upon him) said: “Visit graves, for they will remind you of the Hereafter.” 
          (Narrated by Muslim in his Saheeh). 
          
The Prophet  (peace 
          and blessings of Allaah be upon him) used to teach his Sahaabah, when 
          they visited graves, to say, “Al-salaamu 
          ‘alaykum ahl al-diyaar min al-mu’mineen wa’l-Muslimeen, wa innaa in 
          shaa’ Allaah bikum laahiqoon, nas’al Allaaha lana wa lakum al-‘aafiyah 
          (Peace be upon you, O believing and Muslim dwellers of this place. We 
          will join you soon, if Allaah wills. We ask Allaah to keep us and you 
          safe).” (Narrated by Muslim in his Saheeh).