Fix API redirect loop problem