The Prophet Muhammad – Allah’s peace and blessings be upon him – said:
Actions are but by intentions, and everyone will have what he intended. So whoever migrated to Allah and His Messenger, he migrated to Allah and His Messenger. But whoever migrated for some worldly benefit, or to take a woman in marriage, then his migration was only to what he migrated to.
Al-Bukhâri, Muslim and others.
Traditionally, Muslim scholars chose to begin their works by quoting this hadîth, or report, from the Messenger of Allah, Muhammad – Allah’s peace and blessings be upon him. Here is a brief commentary taken from Ibn Rajab’s Jâmi’ Al-‘Ulûm wa Al-Hikam, in which he explains the entire Forty Hadîth collection of Al-Nawawi:
Imâm Al-Bukhârî (as Al-Nawawi later did in his Forty Hadîth) begins his Sahîh collection with this hadîth, reminding us that any deed through which Allah’s pleasure is not sought is futile; it will bear no fruits in this life or the hereafter.
‘Abd Al-Rahmân b. Mahdî, the great scholar of hadîth, said, “If I were to compile a work in chapters, I would place this hadîth at the beginning of each one.” He also said, “Whoever wishes to author a book, he should begin with the hadîth about intentions.”
This hadîth forms a fundamental principle of Islâm and an axis around which this way of life revolves.
It is reported that Imâm Al-Shâfi’î said, “This hadîth constitutes a third of all knowledge, and it relates to seventy areas of fiqh (correct understanding of the religion).”
It is reported from Imâm Ahmad that he said, “The foundations of Islâm are upon three hadîth: the one reported by ‘Umar – ‘Actions are but by intentions’, the one reported by ‘Âishah – ‘Whoever does a deed that does not conform to our commands will have it rejected’ and the one reported by Al-Nu’mân b. Bashîr – ‘The halâl and harâm are clear…’”
This hadîth teaches us the principle that acceptance of our deeds and whether or not they are regarded as righteous depends primarily on what the intention behind them is. If the intention is good and pure – to receive Allah’s pleasure and reward, the deed is righteous. Otherwise the deed is futile and false. This is the first thing that needs to be dealt with.
The second condition which needs to be met for our deeds to be accepted by Allah is that they should be in conformity with Islâm’s true teachings as taught to us by the Prophet – peace and blessing be upon him – and as understood and applied by the Righteous Predecessors. Hence, the Prophet stated:
Whoever does a deed that does not conform to our commands will have it rejected.
Al-Bukhârî and Muslim