AMHERST, N.H. — The Republican presidential contenders are tying themselves in knots over immigration.

Newt Gingrich is endorsing a South Carolina law that allows police to demand a person's immigration status — a week after taking heat for advocating a "humane" approach. Rick Perry, though defending Texas' in-state tuition for some illegal immigrants' kids, spent Tuesday campaigning with a hardline Arizona sheriff in New Hampshire. And Mitt Romney is talking tough on immigration in his second White House campaign, though he previously supported the idea of allowing some illegal immigrants to stay in the U.S.

Meanwhile, many voters say immigration won't determine which candidate they'll back for the GOP nomination. Instead, they say they're focused squarely on the economy and jobs.

"In light of the economy, questions about immigration policy are less egregious," said Loras Schulte, an evangelical conservative from northeast Iowa.

So what gives?

The contortions by the Republican candidates illustrate the straddle they're attempting on a complex issue. In order to win the Republican nomination, they must court a GOP electorate that is largely against anything that could be called "amnesty" for illegal immigrants. But they can't come off as anti-immigrant, a stance that could alienate the independents and moderates — not to mention Hispanics — they'd need to attract in a general election should they win the party's nod to challenge President Barack Obama.

In 2008, immigration helped shape the Republican presidential race, with John McCain bypassing the leadoff caucus state of Iowa — and planting his flag in New Hampshire — after seeing his standing tank when he backed a plan to give some illegal immigrants an eventual path to citizenship. Still, former Arkansas Gov. Mike Huckabee won the caucuses that year despite having backed tuition benefits in his state for children of illegal immigrants. And McCain ended up winning the nomination despite his position.