diff --git a/pathologic.module b/pathologic.module
index bfa016b..e04b41e 100755
--- a/pathologic.module
+++ b/pathologic.module
@@ -98,7 +98,21 @@ function _pathologic_filter($text, $filter, $format, $langcode, $cache, $cache_i
             $parts['path'] !== $base_url_parts['path']
           )
         ) {
-        // Add it to the list.
+          // if the $parts has no scheme and no hosts and that the path doesn't start with a /
+          // then it is probably a simple domain name (example.org).
+          if (isset($parts['path']) && !isset($parts['scheme']) && !isset($parts['host'])) {
+            if (strpos($parts['path'], '/') !== 0) {
+              // try to construct it again
+              $tmp = parse_url("http://" . $parts['path']);
+              if (isset($tmp['scheme']) && isset($tmp['host'])) {
+                if (!isset($tmp['path'])) {
+                  $tmp['path'] = '/';
+                }
+                $parts = $tmp;
+              }
+            }
+          }
+          // Add it to the list.
           $filter->settings['local_paths_exploded'][] = $parts;
         }
       }
@@ -147,6 +161,7 @@ function _pathologic_replace($matches) {
     foreach ($settings['current_settings']['local_paths_exploded'] as $exploded) {
       if (isset($exploded['host']) && $exploded['host'] === $parts['host']) {
         $found = TRUE;
+        $local_path = $exploded;
         break;
       }
     }
@@ -154,6 +169,19 @@ function _pathologic_replace($matches) {
       return $matches[0];
     }
   }
+  // if url looks like /bananas/baz it is also considered local
+  if (!isset($exploded['host']) && !isset($exploded['scheme']) && strpos($parts['path'], "/") === 0) {
+    // find a local_path that correspond to the url (/banana for instance)
+    foreach ($settings['current_settings']['local_paths_exploded'] as $exploded) {
+      if (isset($exploded["path"]) && strpos($parts['path'], $exploded["path"]) === 0) {
+        $local_path = $exploded;
+      }
+    }
+  }
+  // remove possible basepath from path
+  if (isset($local_path) && isset($parts['path']) && strpos($parts['path'], $local_path["path"]) === 0) {
+    $parts['path'] = drupal_substr($parts['path'], drupal_strlen($local_path["path"]));
+  }
   // First, "files:" support. This is fairly easy.
   if (isset($parts['scheme']) && $parts['scheme'] === 'files') {
     // Can we create a file URL for it?
@@ -170,12 +198,17 @@ function _pathologic_replace($matches) {
   // root is at http://example.com/drupal/ and the URL looks like
   // http://example.com/drupal/foo or /drupal/foo
   if (isset($parts['path'])) {
+    // if path contains the current installation path ($base_path)
     if (strpos($parts['path'], $base_path) === 0) {
       $parts['trimmed_path'] = drupal_substr($parts['path'], drupal_strlen($base_path));
     }
     else {
       $parts['trimmed_path'] = $parts['path'];
     }
+    // remove the first / of the trimmed_path
+    if (strpos($parts['trimmed_path'], '/') === 0) {
+      $parts['trimmed_path'] = drupal_substr($parts['trimmed_path'], 1);
+    }
     if ($parts['trimmed_path'] === '') {
       // Okay, if we just ended up with an empty string, then what happened is
       // they linked to the front page of their Drupal installation using non-
diff --git a/pathologic.test b/pathologic.test
index 7318d21..cb4f379 100644
--- a/pathologic.test
+++ b/pathologic.test
@@ -113,10 +113,13 @@ class PathologicTestCase extends DrupalWebTestCase {
         );
       }
     }
+    // reset clean_url
+    variable_set('clean_url', TRUE);
+
     // Test internal: and also considered local
     $filter->settings = array(
       'absolute' => TRUE,
-      'local_paths' => "http://example.com/qux\nexample.org\/bananas",
+      'local_paths' => "http://example.com/qux\nexample.org\n/bananas",
     );
     $filter->format++;
     $this->assertEqual(
