You may recall the Yehoshua was one of the twelve meraglim (spies), who were sent by Moshe to investigate the Land and its inhabitants in parshas Shlach (Numbers 13). Yehoshua and Kalev ben Yefuneh (Caleb) were the only two who delivered a positive report and were the only members of their generation to enter the Land. Now, Yehoshua sent two spies to investigate the city of Jericho. They stayed at the house of a woman named Rachav (Rahab), who was a “woman of ill-repute.” Despite her occupation, she was a righteous woman and she concealed the spies from the King of the city who had heard rumors of their arrival. She gave the King misdirection and sent his soldiers on a wild goose chase.
In exchange for saving their lives, the spies agreed to spare Rachav and her family when the city would be invaded. This promise was conditional, however, on Rachav hanging a red string from her window so that her apartment, which was in the city walls, could be identified.
Rachav later converted to Judaism, married Yehoshua himself, and is the ancestor of several prophets, including Yirmiyahu (Jeremiah).
Excerpted from The OU’s Nach Yomi