Top level redirect moved at the top

Top level checks that could result in a redirect should be at the top
always, we don't want to waste resources including files and executing
code and after that do a redirect