Stand by your man. Melissa Sanders-Rivera says that’s exactly what she did while her husband, Juan Rivera, was in prison for rape and murder.

And her devotion should count for something now that the couple is getting divorced, according to her attorney, like an equitable cut of the $20 million settlement he received after he was exonerated, set free and sued for wrongful conviction.

An appeals court ruled earlier this month that Rivera’s settlement is “marital property” and up for grabs in the couple’s divorce.

After serving 20 years in prison for the rape and murder of 11-year-old Holly Staker in Waukegan, Rivera was cleared by DNA evidence and released.

Rivera and Sanders’ courtship took place while Rivera was in prison. The couple married in October 2000. He was set free in 2012 and filed for divorce two years later.

Sanders-Rivera, 48, visited her husband hundreds of times and wrote him stacks of letters, according to her attorney, Brian Schroeder.

“She believed in Juan, believed in his innocence and fell in love with him,” Schroeder said, adding that Sanders-Rivera helped persuade Northwestern University’s Center for Wrongful Convictions to take up his case.

“She was his beacon, so to speak, and something he could hang onto at night,” Schroeder said. “And now that he’s out, that should not be tossed aside as some meaningless contribution from an outsider.”

Attorney Michael Berger, who represents Rivera, 43, said “it will be up to a trial court to decide if she was a so-called ‘beacon.'”

The reality of the case, Berger said Thursday, “is nothing close to the representation that Mr. Schroeder provided.”

Berger said an appeal with the Illinois Supreme Court to remove the settlement money from the table is pending.

Schroeder expects the case to go to trial before a Cook County judge at some point next year.

Sanders-Rivera is unemployed and lives in the northwest suburbs.

“My professional opinion is that she, meaning his wife, will receive little to none of his settlement,” Berger said.

The amount being squabbled over, after paying taxes and attorney fees, is $11.4 million, Berger said.