Jami` at-Tirmidhi, Book 22, Hadith 30 (In-Book)

Narrated 'Umar bin Al-Khattab: That the Messenger of Allah said: "Deeds are but with intentions, and for the man is only what he intended. So one whose emigration was to Allah and His Messenger, then his emigration was to Allah and His Messenger. And one whose emigration was to the world, to attain some of it, or woman, to marry her, then his emigration was to what he emigrated. [Abu 'Eisa said:] This Hadith is Hasan Sahih. Malik bin Anas, Sufyan Ath-Thawri and more than one of the A'immah narrated this Hadith from Yahya bin Sa'eed. And we do not know of it except as a narration from Yahya bin Sa'eed Al-Ansari. 'Abdur Rahman bin Mahdi said: "It is necessary that we put this Hadith in every chapter."

حَدَّثَنَا مُحَمَّدُ بْنُ الْمُثَنَّى، حَدَّثَنَا عَبْدُ الْوَهَّابِ الثَّقَفِيُّ، عَنْ يَحْيَى بْنِ سَعِيدٍ، عَنْ مُحَمَّدِ بْنِ إِبْرَاهِيمَ، عَنْ عَلْقَمَةَ بْنِ وَقَّاصٍ اللَّيْثِيِّ، عَنْ عُمَرَ بْنِ الْخَطَّابِ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ إِنَّمَا الأَعْمَالُ بِالنِّيَّةِ وَإِنَّمَا لاِمْرِئٍ مَا نَوَى فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى اللَّهِ وَإِلَى رَسُولِهِ فَهِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ وَمَنْ كَانَتْ هِجْرَتُهُ إِلَى دُنْيَا يُصِيبُهَا أَوِ امْرَأَةٍ يَتَزَوَّجُهَا فَهِجْرَتُهُ إِلَى مَا هَاجَرَ إِلَيْهِ ‏" ‏ ‏.‏ قَالَ أَبُو عِيسَى هَذَا حَدِيثٌ حَسَنٌ صَحِيحٌ ‏.‏ وَقَدْ رَوَى مَالِكُ بْنُ أَنَسٍ وَسُفْيَانُ الثَّوْرِيُّ وَغَيْرُ وَاحِدٍ مِنَ الأَئِمَّةِ هَذَا عَنْ يَحْيَى بْنِ سَعِيدٍ وَلاَ نَعْرِفُهُ إِلاَّ مِنْ حَدِيثِ يَحْيَى بْنِ سَعِيدٍ الأَنْصَارِيِّ ‏.‏ قَالَ عَبْدُ الرَّحْمَنِ بْنُ مَهْدِيٍّ يَنْبَغِي أَنْ نَضَعَ هَذَا الْحَدِيثَ فِي كُلِّ بَابٍ ‏.‏

sunnah.com