How to put bad boy  hubby ANTONIO BANDERAS in his place? MELANIE GRIFFITH gets cozy with the NEAREST hunk around!

ON close pal Demi Moore’s advice, Melanie Griffith has shored up her shaky marriage by cozying up to another man – her current co-star, “Hawaii Five-O” hunk Scott Caan!

As The ENQUIRER recently re­vealed, the “Working Girl” star’s 16-year union with Latin heart­throb Antonio Banderas, 51, is teetering on divorce due to his non­stop flirting with gorgeous babes.

So Melanie sought the help of her friend Demi, whose marriage to “Two and a Half Men” star Ashton Kutcher collapsed over his alleged cheating, sources say.

“Melanie has been an emotional mess over Antonio’s wandering eye,” an insider told The ENQUIRER. “But when Demi told her to throw the flirting back in Antonio’s face, she abruptly changed tactics. Melanie decided to make Antonio take no­tice by getting close to Scott.”

The 54-year-old actress – who’s been tight with Demi since they co-starred in the 1995 drama “Now and Then” – and Scott, 35, play mother and son on stage in “No Way Around But Through,” which opened on June 3 in Los Angeles.

“At first Scott was just a shoulder to cry on for Melanie, but they’ve grown very close, very quickly,” said the source.

“Their scenes are intimate, and there’s no denying the mutual at­traction and affection between them. Some days they spend up to 18 hours working together, and they’ve shared cozy dinners and lunches.”

Melanie’s plan has worked like a charm on Antonio – who was caught getting overly friendly with two beauties at the recent Cannes Film Festival in France and with a young Melanie look-alike at a Cancun nightclub.

“When Antonio got wind of how close his wife and Scott have gotten, he raised holy hell with Melanie,” said the source.

“He swore up and down that he’d never cheat on her and begged her to overlook his recent behavior so they can get their marriage back on track.

“Only time will tell if Melanie and Antonio can ultimately stave off the Big D. But for now she’s got him where she wants him – thanks to her good friend Demi, and her hot co-star Scott.”