The actions are but judged according to intentions

It is related by Umar Ibn al-Khattab (رضى الله تعالى عنه ) that he heard the Messenger of Allah (صلى الله عليه وسلم ) say: The actions are but judged according to intentions; and to every man is due what he intended. Thus, whosoever migrates for the sake of Allah (SWT) and His Messenger (صلى الله عليه وسلم ) (and there is no other motive of his migration except compliance with the commands of Allah (SWT) and his Prophet (صلى الله عليه وسلم ) and winning of their good pleasure), his migration is accounted for the sake of Allah and His Messenger (صلى الله عليه وسلم ) (and doubtlessly, he is to true Muhajir- Emigrant- and shall receive the recompense prescribed for Hijrat-Migration-towards Allah and His Messenger (صلى الله عليه وسلم )); and whosoever migrates for the sake of this world or to wed a woman (his migration will not be for Allah and the Prophet [صلى الله عليه وسلم ]), and will be accounted only for the purpose for which it is intended. (Bukhari and Muslim)