These two lines have to reference the same file name. In the top line you say the file is named api.wsgi, and in the second line you say it's flask.wsgi. Which one is it actually? The logic behind these two lines is the first one says "Is the request going through api.wsgi? If so stop processing rules and leave the request as is." The second line basically says, "If the request isn't going to flask.wsgi already redirect the request and process it through the .wsgi file." Since the two lines don't reference the same file name it just endlessly loops.