 The caliph had been residing in nearby Raqqada but chose this new and more strategic location in which to establish his dynasty.The city of al-Mahdiyya is located on a narrow peninsula along the coast of the Mediterranean Sea, east of Kairouan and just south of the Gulf of Hammamet, in modern-day Tunisia.The primary concern in the city's construction and locale was defense.