Do only follow HTTP and HTTPS redirects

Backport of #11032 to stable5