diff --git a/shibboleth_drupalauth.module b/shibboleth_drupalauth.module
index 10fa3b5..4aaca89 100644
--- a/shibboleth_drupalauth.module
+++ b/shibboleth_drupalauth.module
@@ -99,7 +99,17 @@ function shibboleth_drupalauth_continue() {
     drupal_goto('user', array('query' => array('destination' =>'shibboleth_continue')));
   } else {
     $s = shibboleth_drupalauth_settings();
-    drupal_goto($s['idpurl']);
+  
+    if (isset($settings['servers'][ip_address()])) {
+      $datatype = $settings['servers'][ip_address()];
+    } else if (isset($settings['servers']['any'])) {
+      $datatype = $settings['servers']['any'];
+    } else {
+      drupal_set_message(t('No valid IdP location found.'), 'error');
+      drupal_goto('<front>');
+    }
+
+    drupal_goto($datatype['idpurl']);
   }
 }
 
