History and function of the ramparts
The first ramparts were built in the 12th century during the Almoravid dynasty. These tall walls, 8 meters long, made of earth, lime, and mounted on a wooden frame, aimed to protect the medina from attacks by tribes from the High Atlas, initiated by the Almohads. At that time, this initial fortification was far more modest than its current form, but it was especially more economical than if it had been built with stone. The local red clay was free and easily manageable. So much so that when sandstorms or extreme heat destroy part of the ramparts, one can easily rebuild the wall to regain its high-quality defensive function.
The gates of the ramparts
Originally serving to protect the medina, there were few gates. Bab er Robb and Bab Agnaou are the oldest and date from the Almoravid period. They were used to control the entries and exits of traders. As time passed, the medina expanded, the trading tribes that stopped there became more numerous, and other gates appeared. Named after the tribes they served, like Bab Doukkala or Bab Aylen. Eventually, the medina gradually lost its military protection function, and the last gates built serve only as decorative elements and passages. Today, pedestrians and cars freely use the gates, and you're unlikely to come across a guard in any of the 200 towers that stand above the ramparts.
If you want to dive into the history of the ochre city, you now know what to do! A little tip: start your walk just before sunset, the colors will be even more spectacular.