diff --git a/mnet/lib.php b/mnet/lib.php
index 35cbb35..32981e1 100644
--- a/mnet/lib.php
+++ b/mnet/lib.php
@@ -564,12 +564,20 @@ function mnet_get_peer_host ($mnethostid) {
  */
 function mnet_sso_apply_indirection ($url) {
     global $MNETIDPJUMPURL;
+    global $CFG;
 
     $localpart='';
     $urlparts = parse_url($url[1]);
     if($urlparts) {
         if (isset($urlparts['path'])) {
-            $localpart .= $urlparts['path'];
+            $path = $urlparts['path'];
+            // if our wwwroot has a path component, need to strip that path from beginning of the
+            // 'localpart' to make it relative to moodle's wwwroot
+            $wwwrootparts = parse_url($CFG->wwwroot);
+            if (!empty($wwwrootparts['path']) and strpos($path, $wwwrootparts['path']) === 0) {
+                $path = substr($path, strlen($wwwrootparts['path']));
+            }
+            $localpart .= $path;
         }
         if (isset($urlparts['query'])) {
             $localpart .= '?'.$urlparts['query'];
