diff --git a/securepages.module b/securepages.module
index bb10b84..adeb2ab 100644
--- a/securepages.module
+++ b/securepages.module
@@ -77,10 +77,9 @@ 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 = @parse_url($url);
-    $path = drupal_get_normal_path($url['path']);
+    // Extract the path component, and remove the base path.
+    $url = @parse_url($form['#action']);
+    $path = drupal_get_normal_path(substr($url['path'], strlen(base_path())));
 
     $page_match = securepages_match($path);
     $role_match = securepages_roles($user);
@@ -295,4 +294,4 @@ function securepages_can_alter_url($url) {
   }
 
   return TRUE;
-}
\ No newline at end of file
+}
