Fixed all redirects

The current application does not stop the scripts after doing a redirect, which means they will keep running. This poses a security threat, because most redirects are used for access control.

I've fixed this by introducing a new `redirect()` function which sets the `Location` header and immediately stops the script afterwards.