From Jamil Abun-Nasr's A History of the Maghrib (pp. 223-24)
(the Dala'iyya was a Berber Sufi sultanate based in the Middle Atlas that had come to power in the 1640s, and the Andalusians were the Muslims expelled from Spain in 1492):
"[The rebel Ghailan's] successes in the north and an uprising in Fez precipitated a rebellion against the Dala'iyya in Sala in February 1660. It appears that Dala'iyya control lay heavily on the Andalusian chiefs, and with the help of the tribes nearby they sought to regain their independence. The Andalusians and their tribal allies succeeded in besieging Abdulla [governor of Sala and son of Muhammad al-Hajj, the Dala'iyya sultan] in the castle of Sala, and a Dala'iyya army sent to relieve him was defeated in June 1660 by Ghailan. But Abdulla was able to hold out in the castle for sixteen months, about the end of which he received a shipload of provisions from the English who had just occupied Tangier. Abdulla is said to have proposed to the authorities in Tangier an alliance with the Dala'iyya which would enable them to take possession of Sala in return for help against his enemies in the Gharb [the region including Meknes, Sala, and Wazzan]. The dispatch of the provisions seems to have been intended as an expression of interest in the proposed alliance, without the English governor of Tangier Teviot being committed to a definite policy at a time when he was still feeling his way in the complex political situation of northern Morocco. Ghailan's unhostile attitude towards the English takeover in Tangier in 1661 seems to have persuaded the governor not to pursue further the proposed alliance with the Dala'iyya. When in June 1661 Abdulla eventually withdrew from the castle, the Andalusians, now in control, followed an ambivalent policy towards Ghailan. They allowed a commander whom Abdulla had left behind to control the castle, thereby retaining nominal Dala'iyya authority to counterbalance Ghailan's increasing power. This arrangement came to an end in 1664 when the Andalusians of Sala formally recognized Ghailan's sovereignty over the town and agreed to remit to him the taxes levied on trade.
"The shifts in the attitudes of the Andalusians of Sala towards the Dala'iyya sultanate paralleled developments in relations between the Berber sultanate and Fez, and it is very likely that the Andalusians measured the power of the Dala'iyya chiefs by their ability to persuade Fez to accept their rule. Though Fez ceased to be the political capital of Morocco from the middle of the sixteenth century, it continued to constitute the country's political pulse...
"The Dala'iyya sultan was able to bring Fez to recognize his authority once more but he avoided causing fresh disturbance by appointing a Berber to govern it. New Fez was placed under the authority of Abu Abdulla al-Duraidi, chief of Duraid, an Arabian tribe... Old Fez had a special regime in which two local chiefs shared power... By 1662 the two cities of Fez were again in rebellion, and Abdulla, the former governor of Sala, was in vain trying to enter the city with a Berber army. But in September 1663, when Old Fez felt the heavy-handedness of the Duraid tribe..., its leaders voluntarily sought the imposition of direct Dala'iyya rule. By then Muhammad al-Hajj [the Dala'iyya sultan] could no longer control al-Duraidi who had become a brigand-ruler scourging the countryside around Fez and Meknes. So he left Old Fez to fend for itself against the Arabian tribes as best it could. Sala simultaneously broke its last links with the Dala'iyya, and about the same time the Alawite sharifs [who eventually took over the whole country and still rule it today] intensified their activities in north-eastern Morocco."