(Repeats story, text unchanged)
* Rivals exchange rockets, Grad missiles over Tripoli
* Roots of conflict back in 2011 civil war on Gaddafi
* Western powers worried Libya is becoming failed state
By Patrick Markey and Aziz El Yaakoubi
TRIPOLI, July 31 (Reuters) - Booms of outgoing artillery shaking the ground, militia fighters from the remote Libyan mountain town of Zintan hunker down in the passenger terminal to defend Tripoli airport, the biggest prize in the capital.
Across the city a few kilometres away, a commander of a brigade from the port city of Misrata rallies his men to take the airport back.
Three years ago, Zintani and Misratan rebel brigades descended simultaneously on Tripoli from east and west to storm the palaces of Muammar Gaddafi. Now, fighters from the two towns are waging open war in the capital.
"This war is harder than the revolution," said Mohammed, a fighter in a unit allied to the Zintanis, standing in the debris of the airport terminal, dark smoke billowing from a nearby blast. "They want to take the airport, and when you take the airport you take Tripoli."
Across the city at his Tripoli base lined with tanks and trucks mounted with cannons, Hassan Shakka, a commander of Misrata's Central Shield brigade, said his forces were "completing the revolution".
"We are not fighting the Zintanis: we are fighting the remains of Gaddafi's army," he said. "There will be no ceasefire until they leave Tripoli."
Two weeks of shelling have knocked Tripoli International Airport out of commission. A control centre is damaged, nearly 20 jets parked on the tarmac have been hit, burned or destroyed and the passenger terminal sports a gaping hole in its roof.
Grad missiles roar over the city. Fighters have closed off parts of southern Tripoli with blockades and earth barricades. Apartment blocks on the airport road bear bullet and blast marks. Zintan fighters have set up checkpoints on the empty highway where blackened grassland marks recent shelling. More are dug in by the airport with anti-aircraft canons.
"It can still be contained. There is room to negotiate. But it is a very delicate situation," said one Libyan government official. "We are trying to negotiate to slow things down. If it spins too much, you can't stop it and it becomes a hurricane."
The war for Tripoli's airport is not even the only war being fought in Libya. A day's drive away in Benghazi, Libya's second biggest city, followers of a renegade former Gaddafi general are waging street battles against an alliance of militia groups, including Islamist fighters that Washington blames for killing the U.S. ambassador two years ago.
The Benghazi militia alliance has overrun a special forces base and forced irregular forces and the army to retreat.
The collapse of Gaddafi's four decades of single man rule has left Libya an armed free-for-all, where cities, regions, charismatic individuals, urban neighbourhoods and rural tribes all field their own armed forces.
Towns fight towns; Islamists oppose nationalists; federalists rise up against central government; ex-Gaddafi units clash with former revolutionaries - and everyone has guns, artillery, tanks and missiles, taken from the vast arsenals the deposed dictator had stashed across the country.
Western countries, which helped blast Gaddafi out of power with a NATO bombing campaign in 2011, are mostly getting out, shutting and evacuating embassies as the OPEC oil exporter teeters toward becoming a failed state.
With the main airport shut, the Americans left by road escorted by Marines; the French sailed out by sea.
For the past three years, the central government has largely failed to build a national army, instead buying off the loyalty of armed groups by putting individual fighters or whole militia units onto the payroll. Despite taking the government's money, most remain loyal to their commanders, regions or cities.
U.N., U.S. and European special envoys are pushing for a ceasefire and political settlement around a new parliament due to start its work in August. But the negotiations are difficult.
Each brigade claims to be a legitimate armed force authorised by competing factions within ministries or the previous parliament; each claims the entitlement as revolutionary liberators of the capital, and refuses to give up its Gaddafi-era heavy weaponry.
Since the 2011 war, Libya's factional rivalries have flared before, only to be restrained by a tenuous balance of power that Libyan officials and diplomats say comes from the knowledge that neither side can overcome the other.
For now, the main rivalry in the capital is that between Zintan and Misrata, which both played outsized roles in the 2011 war that unseated Gaddafi and parlayed their victory into status as kingmakers in the capital.
Zintan, a rugged Arab garrison town of barely 50,000 people perched among poor Berber villages in the arid heights of the Western Mountains, led an unlikely campaign against much larger Gaddafi forces, bursting through the front to reach the coast and march on Tripoli in a lightning advance. Its militia later captured Gaddafi's son Saif al-Islam, still held in its jail.
Misrata, a thriving port of nearly 300,000 with a mercantile tradition, was the biggest city in the west to hold out against Gaddafi's forces, keeping the revolution's hopes alive under intense bombardment during a months-long siege, before its forces battled their way to the capital.
When Tripoli fell, Misrata and Zintan brigades both rushed in from opposite sides to lay claim to stakes in the capital. Zintan took the civil airport; Misrata and its allies took a military airbase. Since then they have skirmished in turf wars.
Despite their local origins, the militia of both towns have allied themselves to political factions with national ambitions.
The Zintanis, with allied groups called the Qaaqaa and al-Sawaiq brigades which include some former Gaddafi special forces, have sided with the National Forces Alliance, led by Mahmoud Jibril, an interim prime minister after the war.
Zintanis have long complained of their town's neglect by Gaddafi, and say they missed out on Libya's oil wealth. Rivals say they have grown rich from exploiting control of the airport.
Many of the Qaaqaa brigade members are fiercely opposed to what they see as growing Islamist influence in Libya.
On the opposite side, the Misrata brigades, including "Libya Shield" units created by parliament, are allied to Islamist-leaning militias whose allegiance is with the Justice and Construction party, seen as close to the Muslim Brotherhood.
The depth of Misrata's suffering under siege by Gaddafi's forces has become a rallying cry for fighters who accuse the Zintanis of cooperating with ex-Gaddafi figures.
"The revolution didn't finish. It is about perceptions over the future of the country. They both think they can win, but do they go to the brink?" said one Western diplomat. "The hope is that they realise that no side can win."
Opponents of the Islamists blame them for starting the latest violence to scuttle the start of the new parliament, elected in June under a system that required candidates to stand without party affiliation, which cost Islamists some clout.
"What is happening is an attempted strike against election results, which handed more power to the Islamists' enemies," said Ziad Dgheim, a federalist and member of the new parliament.
Now each blames the other as positions harden. Zintan says it is only defending the airport from attack and urged a ceasefire to stop "Libyan blood being spilled."
Ahmed Hadia, spokesman for the Misrata Central Shield Brigade, said his group joined the battle only after Zintan's Qaaqaa and Sawaiq brigades were accused of trying to stage a coup and the government was not strong enough to respond.
The airport struggle is hardly the first time Libya's armed factions tried to decide Libya's future. The last parliament and ministries were repeatedly stormed by armed groups to make demands on the fragile state.
The government blames one Islamist militia for the kidnapping of the prime minister from his hotel room in Tripoli last year. Another federalist ex-rebel blockaded Libya's oil ports for a year to demand more autonomy for the east, halting the exports that form the government's lifeblood.
But Professor Dirk Vandewalle, a Libya expert at Dartmouth College in the United States, said militias had now crossed a threshold by openly attacking institutions like Tripoli airport that before would have been viewed as out of bounds.
"What the militias are saying is we are willing to do whatever it takes to solve this," he said. "This is much more visceral, and it is about the spoils of the state and who will control them. A much larger battle is starting to evolve." (Additional reporting by Ahmed Elumami and Feras Bosalum in Benghazi; Editing by Peter Graff)
Our Standards: The Thomson Reuters Trust Principles.