Added isSecure() function and redirect