Index: Fetcher2.java
===================================================================
--- Fetcher2.java	(revision 629246)
+++ Fetcher2.java	(working copy)
@@ -439,6 +439,7 @@
     private String reprUrl;
     private boolean redirecting;
     private int redirectCount;
+	private boolean ignoreExternalLinks;
 
     public FetcherThread(Configuration conf) {
       this.setDaemon(true);                       // don't hang JVM on exit
@@ -453,7 +454,9 @@
       // backward-compatible default setting
       this.byIP = conf.getBoolean("fetcher.threads.per.host.by.ip", true);
       this.maxRedirect = conf.getInt("http.redirect.max", 3);
-    }
+	    this.ignoreExternalLinks=conf.getBoolean("db.ignore.external.links", false);
+ 
+   }
 
     public void run() {
       activeThreads.incrementAndGet(); // count threads
@@ -582,7 +585,8 @@
                   handleRedirect(fit.url, fit.datum,
                                  urlString, newUrl, temp,
                                  Fetcher.PROTOCOL_REDIR);
-                CrawlDatum newDatum = new CrawlDatum();
+                if (redirUrl!=null) {
+		CrawlDatum newDatum = new CrawlDatum();
                 newDatum.getMetaData().put(Nutch.WRITABLE_REPR_URL_KEY,
                     new Text(reprUrl));
                 fit = FetchItem.create(redirUrl, newDatum, byIP);
@@ -594,6 +598,10 @@
                   // stop redirecting
                   redirecting = false;
                 }
+		} else {
+                  // stop redirecting
+                  redirecting = false;
+		}
                 break;
 
               case ProtocolStatus.EXCEPTION:
@@ -659,6 +667,31 @@
                                 String urlString, String newUrl,
                                 boolean temp, String redirType)
     throws MalformedURLException, URLFilterException {
+      String fromHost = null;
+      String toHost = null;
+
+	if (ignoreExternalLinks) {
+            try {
+              fromHost = new URL(urlString).getHost().toLowerCase();
+            } catch (MalformedURLException e) {
+              fromHost = null;
+            }
+          } else {
+            fromHost = null;
+          }
+
+	if (ignoreExternalLinks) {
+              try {
+                toHost = new URL(newUrl).getHost().toLowerCase();
+              } catch (MalformedURLException e) {
+                toHost = null;
+              }
+              if (toHost == null || !toHost.equals(fromHost)) { // external lin$
+	            LOG.debug(" - ignoring redirect " + redirType + " from " + urlString + " to " + newUrl);
+                return (null); // skip it
+              }
+            }
+
       newUrl = normalizers.normalize(newUrl, URLNormalizers.SCOPE_FETCHER);
       newUrl = urlFilters.filter(newUrl);
       if (newUrl != null && !newUrl.equals(urlString)) {

