Refactor order of index.php to prevent errors when not installed

The order previously would mean that a lot of errors may happen, since we loaded the entire page before attempting to redirect.

Secondly, this will now use a Location header instead of JavaScript if possible, which is a cleaner/faster way of doing the redirect.