diff --git a/libavformat/http.c b/libavformat/http.c
index 579debcd35..32308e117d 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -967,9 +967,11 @@ static int process_line(URLContext *h, char *line, int line_count,
         while (av_isspace(*p))
             p++;
         if (!av_strcasecmp(tag, "Location")) {
-            if ((ret = parse_location(s, p)) < 0)
-                return ret;
-            *new_location = 1;
+            if (s->http_code == 201 || s->http_code >= 300 && s->http_code < 400) {
+                if ((ret = parse_location(s, p)) < 0)
+                    return ret;
+                *new_location = 1;
+            }
         } else if (!av_strcasecmp(tag, "Content-Length") &&
                    s->filesize == UINT64_MAX) {
             s->filesize = strtoull(p, NULL, 10);
