The north German seaports of Hamburg and Bremen are contemplating legal action over alleged Dutch government subsidies for the transport of containers by rail between Rotterdam and Germany.

Hamburg, which is coordinating the challenge, says the subsidies violate European Union competition laws and has asked its lawyers to consider whether there are grounds for a complaint to the European Commission, the EU's executive agency.The ports will decide "within two or three weeks" whether to take their complaint to Brussels, said Hartmunt Schwerdt, a spokesman at the Bremen/ Bremerhaven port authority.

The row between the German and Dutch ports has erupted as the Deutsche Bahn, Germany's state railway, appeals a $14 million fine by the

commission last year for allegedly diverting containers from Rotterdam and Antwerp to Hamburg. The German ports claim Rotterdam is getting an unfair advantage because the Dutch government has suspended rail track user charges for NS Cargo, the state-owned rail freight company, until the year 2000, allowing it to quote cheap freight rates for containers to and from Rotterdam.

Peter Dietrich, president of the Port of Hamburg Users' Association, has said the payments break is a clear breach of EU rules. The Netherlands will do everything to give Rotterdam an advantage over the competition, especially German ports, said Horst Bruggemann, legal executive at Hamburger Hafen-Und Lagerhaus-Aktiengesellschaft, the biggest stevedore in Hamburg.

The ports have locked horns over rail transport because of its crucial role in the fiercely competitive Le Havre-Hamburg range over the next 20 years. But rail transport, heavily promoted by EU governments as an alternative to the continent's congested roads, is Rotterdam's Achilles' heel: barely 10 percent of its inland traffic moves by rail compared with around 50 percent in Hamburg and 30 percent at neighboring Antwerp.

Rotterdam aims to raise rail's share to around 25 percent by the year 2010, but this may be too late to prevent traffic from drifting away. Shipowners have complained bitterly to Rotterdam about its lack of rail links and warned they will move to rival ports if service does not improve.

In terms of container volume, Rotterdam leads the pack, handling the equivalent of 4.5 million 20-foot boxes last year, for a 37 percent share of total traffic in the Le Havre-Hamburg range. And it's gaining on its nearest rivals: container traffic was up 9 percent in the first half of 1995 to 2.4 million TEUs while Hamburg's throughput was 6.7 percent higher at 1.4 million TEUs and Antwerp's was up 10 percent at 1.18 million TEUs.

NS Cargo openly admits it's getting a helping hand from the government as part of a plan to make the company independent from the state with the long-term aim of privatizing it.

"The government is treating the rail track like water," said Rene Holdert, an NS Cargo official in Utrecht. "But it's not unfair competition. The DB and the SNCF (of France) don't have to pay either."

The German railway cross-subsidizes its container tariffs by between 30 percent and 40 percent, according to Mr. Holdert.

Meanwhile, NS Cargo's low rates are boosting its container business out of Rotterdam with traffic up by 20 percent or 32,000 TEUs to 192,000 units, in the first half of 1995. But a lack of track capacity will cramp further growth until the end of the decade.

The rating policy of the Deutsche Bahn, not NS Cargo, will have a critical impact on Rotterdam because Germany is the port's biggest hinterland. With a small domestic market, Rotterdam's fate is in the hands of foreigners, port officials say.

"For Rotterdam, Holland stops 100 kilometers (62.5 miles) away at the German border," said Willem Scholten, director of the Rotterdam Municipal Port Management.

''For years and years we have been complaining about the DB's tariffs," said Hendrik Schut, an executive at Europe Combined Terminals, the stevedore firm that handles over 80 percent of the containers passing through Rotterdam.

Rates aren't the only determining factor, according to Greg Guthrie, an executive with P&O Containers Ltd. in Rotterdam. German shippers are extremely nationalistic and will choose German ports, he said.

But shipowners say the DB, under pressure from the Bonn government to cut its multibillion-dollar losses, is adapting a more commercial, non- nationalistic stance. And that is irking the German ports that have enjoyed an extremely close relationship with the railway.

''I'm trying very hard to get business for Rotterdam," said Georg Bartels, a DB executive based in Rotterdam.

Mr. Schut of ECT said German rail tariffs have fallen, making shuttle services to southern Germany, Italy and Eastern Europe more attractive. But it's an uphill struggle: ECT boosted rail's share of its traffic from 8 percent in 1993 to 9 percent in 1994.

The commission's decision to fine the DB for abusing its dominant position is flawed because it didn't allow for the fact that volume discounts accounted for a large part of the gap between freight rates to Hamburg and to Rotterdam and Antwerp, said Michael Adan, a company official at DB's Frankfurt headquarters. Changing drivers and locomotives at the borders between Germany, Belgium and the Netherlands also raise costs.

The Rotterdam stevedores who filed the original complaint against the DB back in 1991 withdrew from the case after cutting a deal with the German railway. But the commission decided to continue with the investigation.

DB says its commitment to Dutch ports is underlined by the fact that it has formed a joint venture with NS Cargo to boost rail traffic between Germany and the Netherlands.

Some shippers here say the German ports are sore because Rotterdam is finally poised to break into the rail business after the Dutch government approved earlier in the year the construction of a $5 billion all-cargo rail

from the port quays to the German border.

The track, due for completion between 2003 and 2005, will be carrying some 30 million tons of cargo eastward by 2015.

''Hamburg isn't very happy . . . ,but the line has to be built, the infrastructure here isn't good enough," said Mr. Bartels, the DB executive in Rotterdam.

German ports contrast the Dutch government's largess toward Rotterdam with what they see as Bonn's indifference to them. That feeling was compounded recently when German Chancellor Helmut Kohl visited the Dutch port and declared, "For Germany, Rotterdam is the world port."