diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index b3c2e9b..a93b2fc 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -719,6 +719,9 @@ function _filter_html($text, $format) {
   }
 
   if (variable_get("filter_html_nofollow_$format", FALSE)) {
+    // Remove any existing rel attributes.
+    $text = preg_replace('/<a([^>]*) rel="([^"]+)"([^>]*)>/i', '<a\\1\\3>', $text);
+    // Add our own rel=nofollow attribute.
     $text = preg_replace('/<a([^>]+)>/i', '<a\\1 rel="nofollow">', $text);
   }
 
