The Rif has been inhabited by Berbers since prehistoric times. As early as the 11th century BCE, the Phoenicians began to establish trading posts, with approval of or partnership with the local Berbers and started interbreeding thus starting a Punic language on the Mediterranean and Atlantic coasts, and founded cities such as Tetouan, Melilla (Rusadir) and, in the 5th century BCE, Tangier (called Tingi back then). Later the Phoenician power gave way to an independent Carthage city-state, as the major power in the region. After the Third Punic War, Carthage was supplanted by Rome, and the Rif became part of the province of Mauretania. When the latter was divided during the rule of Emperor Claudius, Tangier became the capital of Mauretania Tingitana. In the 5th century CE, the region was raided by the Vandals, and Roman rule came to an end. The region remained under Vandal control until the 6th century when the Byzantines reconquered parts of it.
Flag of the Rif Republic (1921–1926)
In 710, Salih I ibn Mansur founded the kingdom of Nekor in the Rif and Berbers started converting to Islam. Berber Muslim kingdoms started establishing more cities. By the 15th century, many Spanish Moors were exiled from Spain and most of them settled in Western Rif, bringing their culture, Andalusian music, and even establishing the city of Ashawen or Chefchaouen (Accawen meaning "horns" in Berber). Since then, the Rif has suffered numerous battles between Berber kingdoms, Spain and Portugal. In 1415, Portugal invaded Ceuta (Sebta), and in 1490 Spain invaded Melilla (Mlilt). There was a period of peace afterwards, but war between Spain and Morocco broke out again in 1859 in Tetouan, where Morocco was defeated. The Spanish-Moroccan conflicts continued in the 20th century, under the leadership of Abd el-Krim, the Berber guerrilla leader who proclaimed the Republic of the Rif in 1921. The Riffian Berbers won several victories over the Spanish in the Rif War of the 1920s before being eventually defeated. The region was added to Morocco's reign by Spain in April 1956, a month after the former gained its independence from France.