diff --git a/securepages.module b/securepages.module
index f3b9c63..603ba26 100644
--- a/securepages.module
+++ b/securepages.module
@@ -75,9 +75,17 @@ function securepages_form_alter(&$form, &$form_state, $form_id) {
   }
 
   if (isset($form['#action']) && securepages_can_alter_url($form['#action'])) {
-    // Remove the base_path, and extract the path component.
-    $url = substr($form['#action'], strlen(base_path()));
-    $url = drupal_parse_url($url);
+    // Extract the path (without base prefix) and the url object.
+    $parsed_url = parse_url($form['#action']);
+    $path_without_base = substr($parsed_url['path'], strlen(base_path()));
+    if (isset($parsed_url['query'])) {
+      $path_without_base .= '?' . $parsed_url['query'];
+    }
+    if (isset($parsed_url['fragment'])) {
+      $path_without_base .= '#' . $parsed_url['fragment'];
+    }
+
+    $url = drupal_parse_url($path_without_base);
     $path = drupal_get_normal_path($url['path']);
 
     $page_match = securepages_match($path);
