diff --git a/securepages.module b/securepages.module
index 7c3f077..e22eabd 100644
--- a/securepages.module
+++ b/securepages.module
@@ -135,17 +135,28 @@ function securepages_redirect() {
   $page_match = securepages_match($path);
   $role_match = securepages_roles($user);
 
+  $redirect = FALSE;
+  $secure = TRUE;
+
   if ($_POST) {
     // If something has been posted to here then ignore the rules.
   }
   elseif ($role_match && !$is_https) {
-    securepages_goto(TRUE);
+    $redirect = TRUE;
   }
   elseif ($page_match && !$is_https) {
-    securepages_goto(TRUE);
+    $redirect = TRUE;
   }
   elseif ($page_match === 0 && $is_https && variable_get('securepages_switch', FALSE) && !$role_match) {
-    securepages_goto(FALSE);
+    $redirect = TRUE;
+    $secure = FALSE;
+  }
+
+  // Allow modules to alter the redirect logic.
+  drupal_alter('securepages_redirect', $redirect, $secure);
+
+  if ($redirect) {
+    securepages_goto($secure);
   }
 
   // Correct the base_url so that everything comes from HTTPS.
