* Rebels occupy centre of Zawiyah, west of capital
* Town controls Tripoli's main supply route
* Gaddafi government says it is still in control
* Rebels say battle under way for town south of Tripoli
(Updates with quotes from Tripoli residents)
By Michael Georgy
ZAWIYAH, Libya, Aug 14 Libyan rebels raised their flag over a strategic town near Tripoli on Sunday after their most dramatic advance in months cut off Muammar Gaddafi's capital from its main link to the outside world.
The swift rebel advance on the town of Zawiyah, about 50 km (30 miles) west of Tripoli, will deal a psychological blow to Gaddafi's supporters and severs the coastal highway to Tunisia that keeps the capital supplied with food and fuel.
There was no sign Tripoli was under immediate threat from a rebel attack: heavily armed pro-Gaddafi forces still lie between Zawiyah and the capital. Previous rebel advances have often been reversed, despite help from NATO warplanes.
But rebel forces are in their strongest position since the uprising against 41 years of Gaddafi's rule began in February. They now control the coast both east and west of Tripoli, while to the north is the Mediterranean and a NATO naval blockade and there is fighting to the south.
"I hope we can go and attack Tripoli in a few days," said Legun, a taxi driver turned anti-Gaddafi fighter. "Now that we have Zawiyah, we can free Libya," he said.
In a day of action across a swathe of northwest Libya, rebels said they had seized the town of Surman, next door to Zawiyah, there was fighting in the town of Garyan that controls the southern access to Tripoli, and shooting could be heard near the main Libyan-Tunisian border crossing.
Moussa Ibrahim, a spokesman for Gaddafi's government, said Zawiyah and Garyan were "under our full control". He said however there were small pockets of fighting in two other locations in the area around Tripoli.
The coastal highway between Tripoli and Tunisia had not been blocked by the fighting, Ibrahim said in a telephone interview, but foreigners were not being allowed to use the route for now "to save them from any bullets here or there".
Rebels from the Western Mountains region to the south dashed forward into Zawiyah late on Saturday, encountering little sustained resistance from Gaddafi's forces.
Near Zawiyah's central market early on Sunday, about 50 rebel fighters were milling around and triumphantly shouting "Allahu Akbar!" or "God is greatest".
The red, black and green rebel flag was flying from a shop. At the point where it passes through Zawiyah, the main highway linking Tripoli to Tunisia was empty of traffic.
Rebel fighters told Reuters there were still forces loyal to Gaddafi in the town, including snipers who they said had positioned themselves on tall buildings. Bursts of artillery and machinegun fire could be heard.
One rebel fighter said Gaddafi's forces controlled the oil refinery on the northern edge of Zawiyah -- a strategic target because it is the only one still functioning in western Libya and Gaddafi's forces depend on it for fuel.
There were signs the fighting was spreading west from Zawiyah along the coastal highway towards the main Ras Jdir border crossing with Tunisia.
A rebel spokesman called Abdulrahman said a rebel force had attacked Surman, the next town west along the coast from Zawiyah. "They are now in full control of the town. There is no fighting now," said the spokesman.
Two men crossing from Libya into Tunisia spoke of clashes in Sabratha, which neighbours Surman and is the site of an ancient Roman town.
"There are problems in Sabratha. The situation is bad there," said one man, who did not want to give his name, as he crossed over into Tunisia.
At the border crossing itself, Libyan customs and immigration officers were operating as usual, despite reports from local people of clashes between rebels and pro-Gaddafi forces in the area late on Saturday.
A Reuters reporter at the Ras Jdir crossing said that at one point he heard about 10 gunshots from the Libyan side of the border. There was another burst a few minutes later. There was no visible sign of any fighting.
On another front in Sunday's fighting, near Garyan, the sound of heavy gunfire could be heard coming from the town and at least six plumes of black smoke rose into the air, a Reuters reporter in the area said.
"We entered it (Garyan) today," a fighter told Reuters as he stopped in the village of Al-Qawalish on the way to Garyan. "We control 70 percent of Garyan. There is still fighting taking place at the moment."
Rebels, backed by NATO warplanes, have been trying since February to end Gaddafi's rule in the bloodiest of the "Arab Spring" uprisings convulsing the Middle East.
The conflict has been largely deadlocked, but the rebels' advance to the Mediterranean coast near Tripoli represents a major shift in the balance of forces.
However, in the centre of Tripoli on Sunday evening, there was no indication that anything had changed.
Young men played football near the city's central square and others sat outside shops shortly before the day's fasting, for the Muslim holy month of Ramadan, ended.
Most residents interviewed by reporters -- who were accompanied by government minders -- said they did not believe reports of rebel advances and shrugged off the possibility the insurgents could reach the capital.
"Of course we will not let them enter Tripoli," said Mohamed Hasan, a 27-year-old who wore a single bullet around his neck.
Tripoli resident Abdul Rahim Mohammed Tarhouni, 20, said there had been rumours that rebels would rape women if they were to reached the capital.
"Of course we are scared. Of course we are thinking of leaving," he said. But he, like others, said he was ready to fight. "Of course I will defend my country and my people."
The advances around Tripoli were watched with satisfaction from Benghazi in eastern Libya, headquarters of the rebel council which Western powers have recognised as Libya's legitimate representative.
"Everything is positive," said the council's military spokesman, Ahmed Bani, when asked about the fighting in Zawiyah.
Gaddafi says the rebels are armed criminals and al Qaeda militants, and has described the NATO campaign as an act of colonial aggression aimed at stealing Libya's oil.
Zawiyah is the hometown of many rebels battling on the western front and has staged two uprisings against Gaddafi since the revolt broke out against his rule.
Isa Korogle, a 35-year-old unemployed man, said he had been hiding in farmland near Zawiyah because he feared for his life since taking part in an uprising earlier this year.
"It feels like the first day of my life because I'm back in Zawiyah," he said on Sunday. (Additional reporting by Ulf Laessing in Ras Jdir, Tunisia, Missy Ryan in Tripoli, Robert Birsel in Benghazi and Hamid Ould Ahmed in Algiers; Writing by Christian Lowe; Editing by Alison Williams)
Our top photos from the past week.