While watching a rough cut of The Wedding Planner (2001) in Canada, Jennifer Lopez and Cory Rooney brainstormed ideas for its accompanying soundtrack. The two "pulled different thoughts and feelings" from the film's scenes. The scene where Lopez's character is in the backseat of a car listening to Matthew McConaughey and Bridgette Wilson's characters talk about the wedding made Rooney think of the line "ain't it funny how some feelings you just can't deny and you can't move on even though you try". According to Rooney, "all those words and melodies just started coming" to him while watching the scene. After he conceived the idea for "Ain't It Funny," Rooney returned to his home and "roughed out the track" and came up with the song's chorus. He then worked with Lopez for an hour to complete the song.Tommy Mottola was so enthusiastic about the song that he contributed to its melody.Adam Shankman, however, felt that "Ain't It Funny" had too much of a Latin influence for the film, due to its usage of timbales. Lopez disagreed with Shankman and the two later agreed to use "Love Don't Cost a Thing" in the film.
In July 2001, Lopez's number one album J.Lo (2001) was reissued with a murder remix of one of its original singles, "I'm Real". The R&B murder remix of "I'm Real" was written by Ja Rule, who also features on the track. According to Rule, he initially was "just f[uck]ing around" with the track after Lopez's team gave it to him to remix, but it turned out to be "a hell of a record". The remix was successful, topping the Billboard Hot 100 chart for several weeks. It also helped J.Lo to return to the top ten of the US Billboard 200 album chart. The remix allowed Lopez to crossover from Pop to R&B. Rule said this put her in "another zone" and her fans aren't "gonna want the pop version of J. Lo no more, they gonna want the 'I'm Real' version". The rapper enjoyed working with Lopez and called it a "real collaboration" because he actually worked with her in the studio. The success of "I'm Real (Murder Remix)" lead him to begin working on a remix for "Ain't it Funny" the following August, which would later be announced as the lead single to J.Lo 's remix album, J to tha L–O! The Remixes, in December 2001.
Rooney explained: "We had changed the sound of Jennifer Lopez [with "I'm Real"] and we didn't have anything else on the [J.Lo] album we could release as a single. We had to do another remix to keep the momentum going." Then-upcoming artist Ashanti dropped by Irv Gotti's studio in New York. She recalled: "Everyone was there and Ja [Rule] was on the floor playing video games, and they had the beat playing in the background. Chris Gotti, Irv Gotti's brother, said 'Ja's supposed to be writing this record for J-Lo, but it doesn't look like he's going to be doing anything tonight. Why don't you go in there and see what's happening?' So that's exactly what I did." Ashanti wrote two verses and recorded a demo for the new version of "Ain't It Funny" for Lopez. Gotti and 7 flew out to Los Angeles on September 10, 2001 to record the song with Lopez. The song was due to be recorded the following day, but was postponed due to the September 11 attacks. When work resumed on the song, Gotti called Ashanti from Los Angeles asking her to write another verse for the song. She recalled: "I had to write it over the phone and two-way Irv the lyrics."
"Ain't it Funny (Murder Remix)" is a Hip Hop song with a duration of three minutes and forty-nine seconds (3:49). It contains no similarities to the original track. While he was working towards the remix, Ja Rule boasted "I'm about to f--- ya'll up," stating that the song's sampling of Craig Mack's "Flava In Ya Ear" would be "remixed" and "vamped up crazy". He said "It's totally not J. Lo". Over the reworking of the "Flava In Ya Ear" beat, Lopez sings about "a boyfriend who keeps messing up," while Rule and Cadillac Tah "drop rhymes" on the track. Rule raps that he's "Off the wall like MJ in his early days," which is a reference to Michael Jackson's album Off the Wall (1979). The rapper also says "Oh I, never been a sucker for chocha," choca meaning pussy, the slang term for vagina. He continues on to say that people "want" him after they see him "workin' with money," meaning working with Lopez.
While reviewing the original "Ain't It Funny", Billboard's Chuck Taylor said of the remix release, "Sony has got to be kidding, calling it "Ain't it Funny" when not one note of it is held in common with the original. It's a disturbing trend, but one that will surely push J.Lo to a new high."
"Ain't it Funny" was released to appeal to not only pop but "street-leaning" outlets. For the week ending December 29, 2001, "Ain't it Funny" debuted at number 74 on the Billboard Hot 100, a few positions shy of winning the week's "Hot Shot Debut" title. It also debuted at number 75 on the Hot 100 Airplay. In its second week, the song jumped to number 53 on the Hot 100 and 56 on the Airplay chart. The following week, "Ain't it Funny" broke the top 40 of the Hot 100 and the Airplay chart. After its fourth week, the song progressed to number 16 on the Billboard Hot 100, winning the chart's "Greatest Airplay Gainer" title of the week, having jumped to number 17 at the Airplay chart that week. For the week ending February 9, 2002, "Ain't it Funny" jumped from number 12 to ten on the Hot 100 and Airplay chart, making it Lopez's fifth top-ten hit at the time. This week, it once again won the "Greatest Airplay Gainer" title. The next week, again claiming the "Greatest Airplay Gainer" title, the song jumped to number four on both charts, while also entering the top ten of Billboard 's Hot Dance Club Play chart at number eight.
After remaining in the top five of both charts for another three weeks, "Ain't it Funny" peaked at number one on the Hot 100 and Airplay for the week ending March 9, 2002. This week, the single's parent album J to tha L-O! The Remixes returned to number one on the Billboard 200 with sales of 102,000 units, giving her simultaneous number ones. Also this week, the album had reached number five on the magazine's Top R&B/Hip Hop Albums chart while "Ain't it Funny" had reached the same position on the Top R&B/Hip-Hop Tracks chart. Additionally, the song unseated the track "Always On Time" at the summit of the Hot 100, which was coincidentally by Ja Rule featuring Ashanti, two people who worked with Lopez on the remix. For five weeks and well over a month, "Ain't it Funny" remained at number one on the Hot 100 and Airplay chart, before dropping to number three on both charts for the week ending April 20, 2002. The song peaked at number three on the R&B/Hip-Hop Tracks Chart.
The murder remix for "Ain't it Funny" attained moderate success internationally. In the United Kingdom, it peaked at number four, becoming her seventh top-ten hit there. The remix entered the Swiss Singles Chart at number 16 for the week of March 17, 2002. Three weeks later, it peaked at number seven, where it remained for an additional week. "Ain't it Funny" also peaked at number seven in The Netherlands for the week ending March 30, 2002. In total, it spent five weeks in the top ten on the Dutch Singles Chart. The song entered the top twenty in Belgium Flanders, Spain and Denmark.