change redirect mechanism

Now, the redirection is performed when the script is loaded, which make
it a lots more faster.