Fixing redirect loop and restful redirect