Sunan Ibn Majah, Book 37, Hadith 4367 (In-Book)

‘Alqamah bin Waqqas (said) that he heard ‘Umar bin Khattab, when he was addressing the people, saying: “I heard the Messenger of Allah say: ‘Actions are but by the intention and every man will have but that which he intended. So he whose emigration was for Allah and His Messenger, his emigration was for Allah and His Messenger. But he whose emigration was for some worldly benefit or to take some woman in marriage, his emigration was for that which he migrated.”

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

sunnah.com