From the route of Amir-il-Mu’minin (the leader of the Believers) Abu Hafs ^Umar bin al-Khattab, may Allah accept his deeds, who said: I heard the Messenger of Allah, sallallahu ^alayhi wa sallam, say: <<The religious matters are valid only with proper intentions; and one acquires that which he intended. The one whose Immigration was for the sake of Allah and His Messenger, then his Immigration is accepted. And the one whose Immigration was for a worldly gain or for marrying a woman, then his Immigration is for the purpose he intended and is not accepted.>> Narrated by the two Imams of the Scholars of Hadith, Abu ^Abdillah Muhammad bin Isma^il bin Ibrahim bin al-Mughirah bin Bardizbah al-Bukhari, and Abu al-Husayn Muslim bin al-Hajjaj bin Muslim al-Qushayri an-Naysaburi in their two books of As-Sahih which are the most Sahih books that have been compiled.
عَنْ أَمِيرِ الْمُؤْمِنِينَ أَبِي حَفْصٍ عُمَرَ بْنِ الْخَطَّاب رَضِيَ اللهُ عَنْهُ قَال: سَمِعْتُ رَسُولَ اللَّهِ صلى الله عليه وسلم يَقُولُ: ((إنَّمَا الأَعْمَال بِالنِّيَّاتِ ، وَإِنَّمَا لِكُلِّ امْرِئٍ مَا نَوَى، فَمَنْ كَانَتْ هِجْرَتُهُ إلَى اللَّهِ وَرَسُولِهِ فَهِجْرَتُهُ إلَى اللَّهِ وَرَسُولِهِ ، وَمَنْ كَانَتْ هِجْرَتُهُ لِدُنْيَا يُصِيبُهَا أَو امْرَأَةٍ يَنْكِحُهَا فَهِجْرَتُهُ إلَى مَا هَاجَرَ إلَيْهِ)). رَوَاهُ إِمَامَا الْمُحَدِّثِينَ أَبُو عَبْدِ اللهِ مُحَمَّدُ بْنُ إِسْمَاعِيلَ بْنِ إِبْرَاهِيمَ بْنِ الْمُغِيرَةِ بْنِ بَرْدِزْبَه الْبُخَارِيُّ، وَأَبُو الْحُسَيْنِ مُسْلِمُ بْنُ الْحَجَّاجِ بْنِ مُسْلِمٍ الْقُشَيْرِيُّ النَّيْسَابُورِيُّ فِي صَحِيحَيْهِمَا اللَّذَيْنِ هُمَا أَصَحُّ الْكُتُبِ الْمُصَنَّفَةِ.