Sex is readily available in exchange for cash in San Francisco – in many cases, in a business with a license to operate from The City.

In one of the worst-kept secrets in San Francisco, as many as half of The City’s roughly 300 massage parlors serve as fronts for prostitution, according to the San Francisco Department of Public Health.

Now, city officials are hoping that additional restrictions on massage parlors, signed into law by Mayor Ed Lee last month, finally turns off some red lights.

Massage parlors shut down for health code violations or illegal activity now must wait three years before re-opening at the same location. New parlors and some existing parlors must also apply for and receive a conditional use permit from The City’s Planning Department, a lengthy and expensive process that can be derailed by neighborhood opposition to the permit. However, some establishments will be able to continue as normal through a “legitimization program” concocted by Tang's office.

The City’s Department of Public Health can now also no longer deny a permit to a would-be parlor owner charged with a crime – no conviction necessary.

Other tweaks to how The City regulates massage parlors are meant to clear up confusion created by a recent state law that, until now, allowed a parlor to operate under either a state or a city license (or, in as many as 90 other cases, no license at all).

The new rules, which go into effect June 30, represent the third time Supervisor Katy Tang has taken aim at massage parlors, which experts say are often hubs for human trafficking as well as fronts for sex workers.

Well-known and advertised on the Internet, this illegal activity rarely results in criminal prosecutions or even an identified problem business closing.

And in one notorious case, a masseuse caught having sexual intercourse with a client by Health Department inspectors escaped with a $500 fine for inappropriate attire — no police action and no further penalties.

That was five years after then-Mayor Gavin Newsom walked into a massage parlor in a surprise visit and witnessed a masseuse performing a sex act on a client.

Three “brothels” were reported broken up by San Francisco District Attorney George Gascon’s office in 2014. A spokesman for the office could not immediately say if any of the brothels were masquerading as massage parlors.

Parlors whose license is revoked for illegal activity often reopen a short time later in the same location. Of the 78 parlors shut down from 2008 to 2014, 45 reopened — and 20 have closed and re-opened multiple times, according to the Department of Public Health.

Some parlors “are just really horrible examples of human trafficking,” Supervisor Scott Wiener said recently. In rare cases, some parlors house women who are “basically sex slaves… it’s a terrible situation.”

Fixing what some may consider an obvious problem has proved difficult.

Tang’s efforts have often been met by staunch opposition from legitimate massage providers, who say they are unfairly lumped in with obvious criminal fronts.

“There were some concerns we were criminalizing the industry,” Tang said recently. “Unfortunately, there has been some illegal activity happening.”

Adding to the confusion was a 2009 state law that allowed massage establishments an exemption from receiving a city permit if all masseuses received licenses from the California Massage Therapy Council (CAMTC). That also exempted the establishments from stricter City standards, according to health and elected officials.

Tang’s legislation also requires all massage establishments to get a city Health Department license. There are possibly as many as 300 massage parlors in San Francisco. On top of the 146 parlors with Department of Public Health licenses, there are another 90 operating with CAMTC permitting. There could be as many as 90 more with no license at all, according to Cyndy Comerford, a planning and fiscal policy manager with the Department of Public Health.

Unlicensed establishments have 90 days from June 30 to apply for a DPH permit. Establishments that do not conform with land use restrictions have 18 months to apply for and receive a conditional use permit from the Planning Department.

However, finding problem establishments and fly-by-night operators may prove difficult.

Most inspections are complaint-driven, according to the Department of Public Health. Only 120, or just over half, of The City’s Department of Public Health-licensed massage parlors were inspected in 2014.

Of those, 62 were cited for violations, 32 of which had multiple violations.

Correction:This story was updated June 18 to note that new legislation authored by Supervisor Katy Tang provides that a permit will be denied if an operator has been convicted of a crime. The story also now clarifies that Tang’s legislation provides for some existing establishments to get permitting without a conditional use permit if a list of requirements is met.