Rebels tried to cut Nicaragua's major highway today, and ambushes by guerrillas during the weekend killed at least 20 Nicaraguan troops and eight mothers traveling in Army trucks to visit soldiers at a rural Army base, according to government sources and an official government communique.

In addition to the increased fighting in the country's northern mountains, Nicaraguan troops operating in southern Nicaragua, near the Costa Rican border, were reportedly laying siege to a base belonging to the rebel forces of Eden Pastora, known as Commander Zero, trying to deal that impoverished guerrilla effort a death blow.

A bridge on the Pan American Highway near the city of Esteli, 100 miles north of Managua, was damaged by a dynamite attack at 6 a.m. today, according to the Nicaraguan Army, but sources in the northern city said that it was still passable and that the road to provinces farther north was not cut.

The U.S.-backed rebels blew out a bridge on the nation's main highway farther north in Nueva Segovia Province, 140 miles north of Managua, in October 1983, but they have been unable to cut the road closer to the capital. The Pan American Highway connects Nicaragua to its neighbors, Honduras and Costa Rica.

The killing of at least 20 Sandinista militiamen reportedly came yesterday, only a few miles outside Esteli, in an ambush near the town of La Concordia, according to government sources in Managua, who would give no further details.

The spine of mountains that approaches Esteli from the north has been a traditional path for rebels trying to penetrate into the interior from bases in Honduras. During the first half of this year, the Nicaraguan Army said it had cut off those entry routes and had pushed many rebels of the U.S.-backed Nicaraguan Democratic Force back across the Honduran border.

The attempt on the bridge and the ambush of the soldiers was the most serious rebel action around Esteli this year. The same government sources said troops in that city of about 50,000 residents had been put on special alert.

The deaths of the eight mothers and the wounding of 18 other persons came Saturday in a rebel ambush, the Foreign Ministry communique said, assailing what it called "a terrorist act." The attack came as the group was traveling in Army troop trucks along a dirt road in Matagalpa province, on their way to a training camp for draftees at Mulukuku, northeast of Managua, it added.

Those in the trucks were all from the western Nicaraguan cities of Leon and Chinandega and were on the last leg of an all-day journey when the attack came 10 miles from the base, according to the Army. Today there was a group funeral and progovernment rally in Leon, during which President Daniel Ortega accused the Reagan administration of following a "policy of extermination" against Nicaragua. "They are behaving worse than Hitler," he said.

Meanwhile, on the opposite side of the country, Nicaraguan troops were said to be attacking a base at Sarapikqui, on the San Juan River, which forms the border of Costa Rica. The base was said to be one of the largest -- if not the largest -- still run by Pastora, a hero of the Sandinistas' fight against dictator Anastasio Somoza, but who split with the Sandinistas more than three years ago.