Made it work with HTTPS and redirects.