Sahih al-Bukhari, Hadith 3898 ⓘ
Narrated `Umar: I heard the Prophet saying, "The reward of deeds depends on the intentions, so whoever emigrated for the worldly benefits or to marry a woman, his emigration was for that for which he emigrated, but whoever emigrated for the Sake of Allah and His Apostle, his emigration is for Allah and His Apostle."
حَدَّثَنَا مُسَدَّدٌ، حَدَّثَنَا حَمَّادٌ ـ هُوَ ابْنُ زَيْدٍ ـ عَنْ يَحْيَى، عَنْ مُحَمَّدِ بْنِ إِبْرَاهِيمَ، عَنْ عَلْقَمَةَ بْنِ وَقَّاصٍ، قَالَ سَمِعْتُ عُمَرَ ـ رضى الله عنه ـ قَالَ سَمِعْتُ النَّبِيَّ صلى الله عليه وسلم يَقُولُ " الأَعْمَالُ بِالنِّيَّةِ، فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى دُنْيَا يُصِيبُهَا أَوِ امْرَأَةٍ يَتَزَوَّجُهَا، فَهِجْرَتُهُ إِلَى مَا هَاجَرَ إِلَيْهِ، وَمَنْ كَانَتْ هِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ، فَهِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ صلى الله عليه وسلم " .
also referenced under: Book 63, Hadith 124 (In-Book) & Volume 5, Book 58, Hadith 238 (USC-MSA)