Improved error redirect. Improved basic_auth check