Liechtenstein is ablaze with red and gold as it celebrates 40 years of rule by Prince Franz Josef II. His reign has seen the tiny Alpine principally transformed from one of Europe's poor relations into its richest state.

National flags flutter from red-tiled houses, government offices, shops, modern factory blocks and fairy-tale castles set against a background of firs and pines and towering mountains on the shores of the upper Rhine River.

Celebrations reached a climax at the weekend, a few days before the prince's 72nd birthday on Aug. 16, with a concert, reception, presentation of gifts, and a ceremonial Mass, followed by a banquet, a torchlight procession, fireworks and dancing in the narrow streets and squares of this minicapital.

The last remnant of the 19th century confederation of 39 German-speaking states tucked between Austria and Switzerland, Liechtenstein still has no railroad station, airport or radio or television transmitter.

But it has the largest false teeth factory in Europe, and it is the home of an estimated 15,000 to 50,000 "letterbox" companies, most run from abroad, attracted by the principality's tax advantages.

Its 45 industrial plants produce goods that range from highly technical moonshot equipment to boilers, sausage skins and preserved foods, and its postage stamp issues are sought by collectors around the world.

Industrial development since World War II is the main source of wealth of the country, which is only 62 square miles in size and has a population of only 25,000. One out of every three residents is a foreigner.

The gross national product - the total value of goods and services produced - last year averaged an estimated $16,000 per capita, making the land the most affluent in the Western world.

When Prince Franz Josef II, a grandson of Emperor Franz Josef of Austria-Hungary, became ruler on July 26, 1938, as war clouds gathered over Europe, Liechtenstein was still largely agricultural and far from rich.

Closely linked with Austria for 70 years, the principality had been impoverished at the end of World War I by the collapse of the Austrian crown, then the national currency, and recovery was slow.

Between the wars, the prince and his five-man cabinets turned toward Switzerland and through customs, monetary, postal and diplomatic conventions Liechtenstein was integrated into the Swiss economic sphere. Despite the presence of Nazi troops just across the mountains in Austria, the country managed to keep out of World War II.

Today border controls are minimal and in some places only a sign indicates to motorists that they have crossed from Switzerland into the principality.

Franz Joseph is the first head of the ruling family to live permanently in Vaduz in Lichtenstein's 172-year history as a sovereign state. He is also the longest-serving head of state in Europe.

The prince's home, a squat, 700-year-old castle perched on a rock about 350 feet above the main street of Vaduz, is not open to tourists, but each year official guests flock there for gala birthday receptions.

Standing alongside the prince to welcome them is Princess Gina, the Austria he married in 1943. They have four sons and one daughter.

The prince has a retiring disposition and shuns publicity, but he is no mere figurehead. A qualified forestry engineer, he vetoed a hunting law some years ago after it had been approved in a referendum, and he has also spoken out to local politicians when he objected to their projects.

Two years ago, on his 70th birthday, he signed a law giving women the right to vote - but only in communal elections. They still have no vote in national affairs.

The principality's tiny jail is empty - the last prisoner finished his sentence earlier this month - and citizens have been on their best behavior since then.

But Liechtenstein has not officially abolised capital punishment, and a convicted murderer is in a Swiss prison awaiting the result of an appeal of a death sentence imposed on him by a Liechtenstein court last November for killing his wife and two children.

He was sent to the Swiss jail for security reasons. The last execution in Liechtenstein was in 1785.

The first real government crisis broke earlier this year when the two parties in the governing coalition - the Fatherland Union and the Progressive Citizens Party - disagreed about which would get the Foreign Ministry. After 2 1/2 months of deadlock, the prince solved the problem by abolishing the ministry and splitting its functions between two other ministries.

Relations with Switzerland have been largely untroubled until recently, when tension was generated by efforts of the Bern government to persuade Liechtenstein to tighten controls on the monetary policy of the principality, which uses the Swiss franc as its currency.

The Swiss move was promted by upheavals on foreign exchange markets that drove up the value of the franc, and two major banking scandals last year that involved companies in Liechtenstein.

A Swiss Finance Ministry official explained that what Bern wanted was a treaty that would make Swiss decisions automatically applicable in Liechtenstein.

But officials in Vaduz are unhappy about the idea and refuse to talk about the treaty discussions.

Switzerland is not letting this bit of bother dim its good-neighborly participation in the anniversary celebrations. Justice and Police Minister Kurt Furgler will head an official delegation.

And the Swiss Army - which in 1969 almost caused an international incident by accidentally firing five artillery practice shells across the Rhine into the Liechtenstein mountains - is sending a band and 15 cooks.

Their only arms are a battery of field kitchens "goulash cannons" that will feed street revelers throughout the festivities. CAPTION:

Picture 1, PRINCE FRANZ JOSEF II, . . . vetoed a bill, once; Map, no caption, By Dave Cook - The Washington Post; Picture 2, Prince Frans Josef II lives in a castle overlooking the city of Vadux, capital of Liechtenstein. Swiss National Tourist Office