A ribat was originally a fortified structure, organized around a courtyard, with a double story perimeter of rooms. Typically, a ribat be used by religious warriors as an outpost. Its architectural organization is similar to that of a caravanserai, with storage rooms and stables on the ground floor and sleeping quarters on the upper level. As such, the ribat typology lends itself to adaptation for use as a caravanserai.
It is not clear whether the Ribat-i Mahi originally had a militant function, but it did function as a caravanserai, providing lodging for travelers along a trade route. Located along the ancient trade route between Tus (near present-day Mashad) and Sarakhs, the Ribat-i Mahi is known to be the oldest extant example of a ribat. It was built in 1019-1020 by Sultan Gazneli Mahmut in memory of Firdwasi, the author of the Persian epic, the Shahname.
Sources:
Branning, Katharine. "Origins of the Han." 2001-2005.
http://www.turkishhan.org/homebase.htm. [Accessed October 5, 2005; updated October 31, 2013].
"Caravanserais."
http://byegm.gov.tr/yayinlarimiz/NEWSPOT/1999/Nov-Dec/N9.htm [Accessed October 8, 2005; inaccessible October 31, 2013].
Hillenbrand, Robert. . Islamic Architecture: Form, Function, and Meaning, 331,344. Edinburgh: Edinburgh University Press, 2000.
Petersen, Andrew. "Caravanserai."
Dictionary of Islamic Architecture, 51. London: Routledge, 1999. See:
http://archnet.org/library/dictionary/entry.jsp?entry_id=DIA0063Petersen, Andrew. "Ribat."
Dictionary of Islamic Architecture, 246. London: Routledge, 1999. See:
http://archnet.org/library/dictionary/entry.jsp?entry_id=DIA0823