diff --git a/pathologic.module b/pathologic.module
index 27c7108..851c95e 100644
--- a/pathologic.module
+++ b/pathologic.module
@@ -133,15 +133,6 @@ function _pathologic_filter($text, $filter, $format, $langcode, $cache, $cache_i
     $filter->settings['local_paths_exploded'][] = array('path' => $base_url_parts['path'], 'host' => $base_url_parts['host']);
     // We'll also just store the host part separately for easy access.
     $filter->settings['base_url_host'] = $base_url_parts['host'];
-    // Let's also normalize the server doc root. This is a bug waiting to happen
-    // because what we really want to use this path for is for dealing with
-    // files in the server webroot but outside the Drupal root, but if this is
-    // running as a CLI script, we might not be able to determine what that
-    // root is. In that case, we'll use the Drupal root.
-    // @see http://drupal.org/node/1780398
-    $filter->settings['docroot'] = (drupal_is_cli() || empty($_SERVER['DOCUMENT_ROOT']))
-      ? realpath(DRUPAL_ROOT)
-      : realpath($_SERVER['DOCUMENT_ROOT']);
 
     $settings[$filter->format] = $filter->settings;
   }
@@ -213,23 +204,9 @@ function _pathologic_replace($matches) {
     $parts['path'] = '';
   }
 
-  // Check to see if we're dealing with a file. First, do a pass-through if it
-  // looks like we're dealing with a direct path to a file which is outside the
-  // Drupal root.
-  // @see http://drupal.org/node/1763696
+  // Check to see if we're dealing with a file.
   // @todo Should we still try to do path correction on these files too?
-  $filepath = $settings['current_settings']['docroot'] . '/' . $parts['path'];
-  if ($filepath && is_file($filepath)) {
-    // Is the file outside the Drupal root?
-    if (strpos($filepath, DRUPAL_ROOT) !== 0) {
-      return $matches[0];
-    }
-    else {
-      // Linking to a file inside the Drupal root. Okay.
-      $settings['is_file'] = TRUE;
-    }
-  }
-  elseif (isset($parts['scheme']) && $parts['scheme'] === 'files') {
+  if (isset($parts['scheme']) && $parts['scheme'] === 'files') {
     // Path Filter "files:" support. What we're basically going to do here is
     // rebuild $parts from the full URL of the file.
     $new_parts = parse_url(file_create_url(file_default_scheme() . '://' . $parts['path']));
@@ -281,16 +258,27 @@ function _pathologic_replace($matches) {
       // Break out of foreach loop
       break;
     }
+    // Is this is a root-relative url (no host) that didn't match above?
+    // Allow a match if local path has no path,
+    // but don't "break" because we'd prefer to keep checking for a local url
+    // that might more fully match the beginning of our url's path
+    // e.g.: if our url is /foo/bar we'll mark this as a match for
+    // http://example.com but want to keep searching and would prefer a match
+    // to http://example.com/foo if that's configured as a local path
+    elseif (!isset($parts['host']) && (!isset($exploded['path']) || $exploded['path'] == '/')) {
+      $found = TRUE;
+    }
   }
 
-  // Okay, if here, we either found something, or we hit the end of the loop. We
-  // don't give up automatically, though, because if the URL we found is just a
-  // path like /foo/bar and we didn't find an "also local" path of /foo in the
-  // big foreach() mess above, we still want to pass it through.
-  if (!$found && !(isset($parts['path']) && !isset($parts['host']))) {
+  // If the path is not within the drupal root return original url, unchanged
+  if (!$found) {
     return $matches[0];
   }
 
+  // Okay, format the URL.
+  // If there's still a slash lingering at the start of the path, chop it off.
+  $parts['path'] = ltrim($parts['path'],'/');
+
   // Examine the query part of the URL. Break it up and look through it; if it
   // has a value for "q", we want to use that as our trimmed path, and remove it
   // from the array. If any of its values are empty strings (that will be the
@@ -319,31 +307,19 @@ function _pathologic_replace($matches) {
   }
 
   // Let's see if we can split off a language prefix from the path.
-  if (!$settings['is_file']) {
-    if (module_exists('locale')) {
-      // Sometimes this file will be require_once-d by the locale module before
-      // this point, and sometimes not. We require_once it ourselves to be sure.
-      require_once DRUPAL_ROOT . '/includes/language.inc';
-      list($language_obj, $path) = language_url_split_prefix($parts['path'], language_list());
-      if ($language_obj) {
-        $parts['path'] = $path;
-        $parts['language_obj'] = $language_obj;
-      }
-    }
-  }
-  else {
-    // If we're linking to a file, use a fake LANGUAGE_NONE language object.
-    // Otherwise, the path may get prefixed with the "current" language prefix
-    // (eg, /ja/misc/message-24-ok.png)
-    $parts['language_obj'] = (object) array('language' => LANGUAGE_NONE, 'prefix' => '');
+  if (module_exists('locale')) {
+    // Sometimes this file will be require_once-d by the locale module before
+    // this point, and sometimes not. We require_once it ourselves to be sure.
+    require_once DRUPAL_ROOT . '/includes/language.inc';
+    list($language_obj, $path) = language_url_split_prefix($parts['path'], language_list());
+    $parts['path'] = $path;
+    $parts['language_obj'] = $language_obj;
   }
 
-  // Okay, format the URL.
-  // If there's still a slash lingering at the start of the path, chop it off.
-  // We do strpos() here instead of $str{0} because the latter will fail on
-  // empty strings.
-  if (strpos($parts['path'], '/') === 0) {
-    $parts['path'] = substr($parts['path'], 1);
+  // If we didn't previously identify this as a file, check to see if this is a
+  // Drupal menu item.  If it's not, assume it's a file
+  if(!$settings['is_file']){
+    $settings['is_file'] = strlen($parts['path']) > 0 && is_file(DRUPAL_ROOT . '/'. $parts['path']);
   }
 
   // If we get to this point and $parts['path'] is now an empty string (which
