Concurrent with this conquest, the Qing occupied the Altishahr region in modern southern Xinjiang, which had been settled by Muslims who followed the political and religious leadership of Afaq Khoja.
[8] Beginning at that time and lasting for approximately one hundred years, the Āfāqī Khojas waged numerous military campaigns in an effort to retake Altishahr from the Qing.
For the 80 years until the Qing conquest, these two khoja factions governed the Altishahr on behalf of Dzungar Khanate including the six major cities (Aqsu, Kashghar, Khotan, Ush Turfan, Yangihissar, and Yarkand) bordering the Tarim Basin.
[10] At that time, the Altishahr region became part of a fragile Chinese frontier governed by Manchu governors and Turkestani officials including supporters of the Ishāqis.
At that time, Jāhangīr Khoja, the son of Sarimsaq, proposed to the ruler of Khoqand, Umar Khan, that they join as allies and launch a holy war against the Qing.
After participating personally in the battle for 12 days, Madali Khan returned home but left part of the Khoqandian force in Jāhangīr's command.
[22] The Qing responded in the spring of 1827 by sending an expeditionary force of more than 20,000 soldiers to combat the Āfāqī Khoja and by the end of March had recaptured all of their lost territory.
[23] To protect and defend Altishahr from future attacks, the Qing increased troop levels in the territory, rebuilt the westernmost cities, and constructed stronger fortifications.
[24] As such, Madali Khan supported the continuation of the holy war and allowed his highest military leaders, including Haqq Quli, the overall Commander of the army, to lead a large force against the Qing.
[25][26] At Yarkand, Chinese merchants and the Qing military declined to battle openly, taking cover inside fortifications and killing Khoqandi troops from a distance with guns and cannons.
[28] Rather than punish Khoqand for the invasion of 1830, the Qing realized that their former approach of trade sanctions and restrictions was ineffective at stabilizing the territory and preventing conflict.
The Qing fortresses held strong, however, and the excesses of the Āfāqī Khoja invaders alienated the citizens to such an extent that no support was received from the local Muslim community and no popular uprising occurred as it had in previous raids.
In capturing the city, Wālī Khān had the support of the local population at the outset but lost favor for his harsh, tyrannical leadership and the imposition and strict enforcement of dress codes, religious customs and traditions.
[32][33] During his short reign, Wālī Khān also gained notoriety when he infamously killed the German explorer Adolf Schlagintweit for no apparent reason.
As the Qing brought the Taiping army to Shaanxi to deal with the rebels, the authorities suggested that the Han organize formal militia units to protect themselves.
In Altishahr, individuals of different ethnicities, tribal affiliations, social backgrounds and classes united as Muslims and rebelled against the Qing regime.
[43] As the Dungans and their Turkic Muslim allies fought for control of the city of Kashghar, requests for aid were made to the ruler of Khoqand, ‘Ālim Quli, and to the Āfāqī Khoja.
In response, an expedition led by the renown Khoqandi military commander Ya‘qūb Beg was sent from Khoqand to Kashghar in late 1864.
[44][45] Over the next eight months, Ya‘qūb Beg led a coalition of Kyrgyz and Qipchaq tribesmen along with Badakhshi mountaineers and captured Kashghar, Yangihissar, and Yarkand.