From loaded-down camel caravans coming in from the desert to the carpet shops and souvenir stalls of today, Marrakesh is first and foremost a magnificent caravanserai city. Raised and then razed by rival conquerors, the city's fortunes and prominence have ebbed and flowed depending on who was in charge, but since its dusky-pink walls were first erected in the 11th century, trade has always stayed true.

Almoravid Dynasty

The Berber Sanhaja tribe founded the Almoravid dynasty in the 11th century and swept through the south of Morocco, demolishing opponents as they rode north. They pitched their campsite on a desolate swath of land that would become Marrakesh.

Almoravid Berber leader Youssef ben Tachfine and his savvy wife Zeinab recognised its strategic potential, and built ramparts around the encampment in AD 1062. The Almoravids established the city’s khettara (underground irrigation system) and signature pink mudbrick architecture.

At the age of almost 80, Youssef ben Tachfine launched successful campaigns securing Almoravid control of Andalucia. Marrakesh, once just a patch of dirt, became the operational centre of an empire that stretched right up to Barcelona’s city limits.

Almohad Dynasty

Almohad warriors stormed the city in 1147 and left only the plumbing and the Koubba Ba’adiyn intact. Almohad ruler Yacoub Al Mansour remodelled Marrakesh with a fortified kasbah, glorious gardens, qissaria (covered markets), a rebuilt Koutoubia and a triumphal gate (Bab Agnaou). But the Almohads lost their showpiece to the Merenids in 1269, who turned royal attention to Meknès and Fez.

Saadian Dynasty

After centuries of playing second fiddle under Merenid rule, Marrakesh regained its crown in the 16th century, when the Saadians established their dynasty in the city. Marrakesh thrived as the crux of lucrative sugar-trade routes, and a trading centre for Christians and a protected mellah (Jewish quarter) were established in 1558. Ahmed Al Mansour Ed Dahbi (the Victorious and Golden) paved the Badi Palace with gold and took opulence to the grave in the gilded Saadian Tombs.

Alawite Dynasty

The Saadian dynasty crumbled in the 17th century, paving the way for the Alawites to seize the reins. Alawite leader Moulay Ismail preferred Meknès to Marrakesh, and moved his headquarters there – though not before looting the Badi Palace. Stripped of its role as the imperial base, Marrakesh entered its Wild West period with big guns vying for control. Those who prevailed built extravagant riads, though much of the population lived hand to mouth in crowded fondouqs (rooming houses).

French Protectorate

After 1912, when Morocco was handed to the French protectorate, Thami El Glaoui was installed as pasha of Marrakesh. While he went to work terrorising southern Morocco, French and Spanish colonists were busy building themselves a ville nouvelle (new town) outside of Marrakesh's city walls.

Post Independence

After independence in 1956, Marrakesh was left without a clear role and resumed its fallback career as a caravanserai – becoming the nation’s breakaway success. Roving hippies built the city’s mystique in the 1960s and ’70s, and visits by the Rolling Stones, Beatles and Led Zeppelin gave the city star power. In the 1990s private medina mansions were converted into B&Bs, just as low-cost airlines delivered weekenders to brass-studded riad doors.