Rehane Reis has always seen the good side of favelas, which she recently shared during a tour of the vast Rocinha favela with a group of Brazilian tourists. (Juan Forero/For the Post)

The views were heart-stopping: the famous beaches of Ipanema, the imposing Sugar Loaf Mountain, the choppy blue Atlantic. The downside of the property that Andreas Wielend wanted was that it was in one of Rio’s notorious favelas, the violent slums clinging to the city’s picturesque hillsides.

But as Rio de Janeiro remakes itself for soccer’s 2014 World Cup and the 2016 Olympics, several intrepid companies, a score of city agencies and even a few foreigners are wandering into the city’s once-forbidden favelas in search of opportunities. Wielend, a 33-year-old Austrian telecommunications engineer, reasoned that the advantages outweighed the shortcomings.

So, two years ago, he paid $10,000 for a spacious house 1,000 feet up in the Vidigal favela and opened a little hotel, which has been a hit not just with young American and European travelers but also with locals, who venture up for rollicking parties from the glittering city below.

“I saw how close it is to everything, and there’s the beach and the view. And for me it was all this and that it was becoming a normal neighborhood,” Wielend said. “The favelas are definitely changing now.”

Rio is carving out tunnels, re-engineering highways, adding subway stations and redesigning its port and city center — all part of a feverish statewide infrastructure development program that will cost nearly $9 billion ahead of the Olympics, the governor of Rio de Janeiro state, Sergio Cabral, recently announced.

But Ricardo Henriques, president of Rio’s urban planning institute, said there is also a strong push to incorporate the slums into the fabric of the rest of the city. It means loosening the grip of brazen drug gangs that run favelas as their fiefdoms, introducing city services and legalizing businesses that had operated as part of a vast, unregulated underground economy.

“It’s a huge experimental stage. Everything is new,” said Daniela Tavares, a city economist overseeing new programs in the favelas. “It’s a new environment for all of us, for the community, the government, all of us.”

The favelas, founded more than a century ago by the rural poor, many of them black, have come to symbolize the great gulf between the wretched and the affluent in one of the world’s most inequitable societies. In Rio, the divide is simply more obvious than in other Brazilian cities because the favelas are often located a stone’s throw from some of the world’s most prized real estate.

The city’s efforts to bring order to the favelas began with a “pacification” program in which police pushed drug gangs out of key areas and for the first time installed a permanent law enforcement presence, led by units of specially trained community policing officers.

“Before, we would go into a community, carry out an operation and then we would leave,” said police captain Glauco Schorcht, commander of a favela called Providencia in Rio’s city center. “This community is 113 years old, and it’s been practically abandoned by the state for 113 years. Now, there are services coming in that did not exist before.”

The units have yet to arrive in most of Rio’s favelas, home to 1.2 million of the city’s 6 million people. The city also still has what Human Rights Watch calls a serious problem of police officers killing hundreds of suspects every year, often under questionable circumstances. But during the past decade, the homicide rate has been cut nearly in half in Rio, to 25.8 killings per 100,000 residents.

That is bringing in people such as Taciana Abreu, 28, who has lived all her life in Rio but had never considered entering a favela. “I was afraid to come,” she explained, sheepishly.

For the past five months, Abreu has led tours of favelas for clients of the advertising agency at which she works, NBS. They have included the Oi telecom company, the fast-food restaurant chain Bob’s and Coca-Cola. NBS’s goal has been to show off the potential in favelas such as Providencia, which is to be revamped along with the nearby port.

“The regular citizen that’s living his life in this town needs to know and see with his own eyes what’s happening here,” she said, stopping to chat during a recent tour.

Providencia, with its sweeping views of downtown Rio, was a fast sell for visitors such as Mariane Maciel, another NBS employee, who predicted that favela residents would soon enter the lower middle class. Raoni Lotar, 30, who works at Coca-Cola, said it was clear from what he had seen that the favelas were being “integrated into our city.”

Another visitor on Abreu’s tour, Wellington dos Santos, said his employer, IESA, an oil services company, has committed itself to the favela by training welders and electricians.

Milene da Silva Costa, who lives in Providencia, is among those on track to land a job as a welder at IESA. “Before, there were not many opportunities for people in these communities, who were seen as people you could not count on,” Costa said.

Indeed, the presiding wisdom for middle-class residents of Rio had been that the favelas were to be avoided. That spurred Rejane Reis to offer guided tours for foreign tourists in Rocinha, a sprawling favela that is home to an estimated 250,000 people.

But one crisp morning last month, it was middle-class Brazilians who tagged after Reis as she led them past bustling street stalls, along narrow passageways and up a steep hillside. She talked about how residents jerry-rig cables to siphon power from the electric grid, pointed to newly painted homes and warned visitors about drug gangs lurking in the shadows.

“In this part, it’s forbidden to take pictures,” she told the tour group along one stretch.

That added a touch of excitement for Ana Carolina dos Santos, a teenage tourist from Sao Paulo.

“Yes, I’m loving it!” she said. “It’s a new experience for me.”