LONDON — The contents of the will of Prince Philip, the late husband of Queen Elizabeth II, are to remain secret for at least 90 years, a High Court judge ruled.

Philip, the Duke of Edinburgh and the longest-serving royal consort in British history, died in April at Windsor Castle. He was 99.

As is the convention after the death of a senior royal, an application was made to the Family Division at London’s High Court that Philip’s will remain sealed and not available to the public, as most wills are after being granted probate.

Andrew McFarlane, the president of the court’s Family Division, ruled in favor of the royal request.

“The degree of publicity that publication would be likely to attract would be very extensive and wholly contrary to the aim of maintaining the dignity of the Sovereign,” McFarlane said in a ruling published Thursday.

He said that the will should be sealed and that “no copy of the will should be made for the record or kept on the court file.”

While it is not unusual for a senior royal to seek this kind of privacy, this was the first time that a judge had published the reasons for allowing the exception.

“There is a need to enhance the protection afforded to truly private aspects of the lives of this limited group of individuals in order to maintain the dignity of the Sovereign and close members of Her family,” McFarlane said.

McFarlane also said that he is the custodian of a safe with more than 30 envelopes containing sealed royal wills, including those of the Queen Mother and the queen’s sister, Princess Margaret. They both died in 2002.

He said the oldest envelope contains the will of Prince Francis of Teck, Queen Mary’s younger brother and great uncle of Queen Elizabeth II. He died in 1910 at age 40 after developing pneumonia.

According to some reports, the royal family sought to avoid scandal and seal his will after discovering the prince had left valuable emeralds to his mistress, the Countess of Kilmorey. Those gems were later “quietly bought back for Queen Mary to wear at the time of her husband's coronation,” according to the Telegraph.

Queen Elizabeth II’s lawyers and the attorney general argued for Philip’s will to be sealed for 125 years, but the judge ruled that 90 was “proportionate and sufficient.”

At that point, the will is to be examined by lawyers for the monarch, and others, who will determine at that stage whether it will be made public.

McFarlane said that some royal wills may never see the light of day.

“There may be circumstances where it would not be appropriate for a Royal will to be unsealed even after that period, whether in full or in part,” he wrote.