It looks like you just need to work on your logic a little. Your second if clause would grab a lot of the same URIs as the first one, unless there's been something added to the "demo" in the uri.
I'd recommend changing the logic of the second if clause to be a little more specific in looking for a uri that has demo as well as something else, so that users won't end up getting redirected twice.
As it stands right now, the user comes in with a URI of "demo", gets redirected to "demo1" then gets redirected again because that still matches the regex in the second if clause.
-Colin