TRIPOLI, Libya  Each side of the conflict in Libya pushed forward on Saturday as militia forces loyal to Col. Muammar el-Qaddafi launched a second day of attacks on the rebel-held city of Zawiyah, just 30 miles west of the capital, and a ragtag rebel army moving from the east won its first ground battle to take the oil port of Ras Lanuf, about midway down the Mediterranean coast.

Both sides were girding for a confrontation in the coming days at the port of Surt, the town where Colonel Qaddafi was born and which blocks the rebels’ progress toward the capital, Tripoli, where extremely heavy gunfire could be heard in the center of the city before dawn Sunday.

Eighteen days after it began with spirited demonstrations in the eastern city of Benghazi, the Libyan uprising has veered sharply from the pattern of relatively quick and nonviolent upheavals that ousted the leaders of Tunisia and Egypt. Instead, the rebellion here has become mired in a drawn-out ground campaign between two relatively unprofessional and loosely organized forces  the Libyan Army and the rebels  that is exacting high civilian casualties and appears likely to drag on for some time.

That bloody standoff was evident on Saturday in Zawiyah, the northwestern city seized by rebels a week ago, where the government’s attacks raised puzzling questions about its strategy. For the second day in a row its forces punched into the city, then pulled back to maintain a siege from the perimeter. Hours later, they advanced and retreated again.