Index: conf/global_settings.py
===================================================================
--- conf/global_settings.py	(revision 1868)
+++ conf/global_settings.py	(working copy)
@@ -130,6 +130,9 @@
 # Whether to prepend the "www." subdomain to URLs that don't have it.
 PREPEND_WWW = False
 
+# class that will resolve the url
+URL_RESOLVER = 'django.core.urlresolvers.URLResolver'
+
 # List of compiled regular expression objects representing User-Agent strings
 # that are not allowed to visit any page, systemwide. Use this for bad
 # robots/crawlers. Here are a few examples:
Index: core/urlresolvers.py
===================================================================
--- core/urlresolvers.py	(revision 1868)
+++ core/urlresolvers.py	(working copy)
@@ -8,7 +8,7 @@
 """
 
 from django.core.exceptions import Http404, ImproperlyConfigured, ViewDoesNotExist
-import re
+import re, types
 
 class Resolver404(Http404):
     pass
@@ -58,18 +58,23 @@
             raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
 
 class RegexURLResolver(object):
-    def __init__(self, regex, urlconf_name):
+    def __init__(self, regex, url_patterns):
         # regex is a string representing a regular expression.
-        # urlconf_name is a string representing the module containing urlconfs.
+        # urlconf_name is a string representing the module containing urlconfs, or
+        # a tupple with parsed urlpatterns
         self.regex = re.compile(regex)
-        self.urlconf_name = urlconf_name
+        if isinstance(url_patterns, types.StringTypes):
+            self.urlconf_name = url_patterns
+        else:
+            self._url_patterns = url_patterns
+            
 
     def resolve(self, path):
         tried = []
         match = self.regex.search(path)
         if match:
             new_path = path[match.end():]
-            for pattern in self.urlconf_module.urlpatterns:
+            for pattern in self.url_patterns:
                 try:
                     sub_match = pattern.resolve(new_path)
                 except Resolver404, e:
@@ -86,14 +91,18 @@
         except AttributeError:
             try:
                 self._urlconf_module = __import__(self.urlconf_name, '', '', [''])
-            except ValueError, e:
+            except (ValueError, ImportError), e:
                 # Invalid urlconf_name, such as "foo.bar." (note trailing period)
                 raise ImproperlyConfigured, "Error while importing URLconf %r: %s" % (self.urlconf_name, e)
             return self._urlconf_module
     urlconf_module = property(_get_urlconf_module)
 
     def _get_url_patterns(self):
-        return self.urlconf_module.urlpatterns
+        try:
+            return self._url_patterns
+        except AttributeError:
+            self._url_patterns = self.urlconf_module.urlpatterns
+            return self._url_patterns
     url_patterns = property(_get_url_patterns)
 
     def _resolve_special(self, view_type):
@@ -109,3 +118,56 @@
 
     def resolve500(self):
         return self._resolve_special('500')
+        
+class URLResolver(RegexURLResolver):
+    def __init__(self, request, urlconf_name):
+        RegexURLResolver.__init__(self, r'^/', urlconf_name)
+
+class HostURLResolver(RegexURLResolver):
+    """
+    The HostURLResolver resolves paths like URLResolver, but only on matching hostnames.
+    Note: The urlpatterns have a different layout.
+
+    urlpatterns = (
+    (r'^localhost$', patterns('',
+         (r'^admin/', include('django.contrib.admin.urls.admin')),
+        ),
+    ),
+    # default view, matches always, even when no HTTP_HOST is sent (HTTP 1.0)
+    (r'', patterns('',
+        ...
+        ),
+    ),
+    )
+    """
+    
+    def __init__(self, request, urlconf_name):
+        self.request = request
+        self.urlconf_name = urlconf_name
+    
+    def resolve(self, path):
+        host = self.request.META.get('HTTP_HOST')
+        # if IGNORE_HOST_PORT is true, we remove the port from 
+        # HTTP_POST and match only the hostname
+        try:
+            if self.urlconf_module.IGNORE_HOST_PORT:
+                host = host[:host.rfind(":")]
+        except: pass
+        tried = []
+        for thost, patterns in self.urlconf_module.urlpatterns:
+            # HTTP 1.0 doesn't send a HTTP_HOST so we  can only match  the default
+            # host which is defined as a empty string
+            if thost != "":
+                if host == None:
+                    continue
+                if not re.match(thost, host):
+                    tried.append((thost,  None))
+                    continue
+            try:
+                r = RegexURLResolver(r'^/', patterns)
+                return r.resolve(path)
+            except Resolver404, e:
+                tried.append((host, e.args[0]['tried']))
+                
+        raise Resolver404, {'tried': tried, 'host':host}    
+    urlconf_module = property(RegexURLResolver._get_urlconf_module)
Index: core/handlers/base.py
===================================================================
--- core/handlers/base.py	(revision 1868)
+++ core/handlers/base.py	(working copy)
@@ -51,16 +51,30 @@
         "Returns an HttpResponse object for the given HttpRequest"
         from django.core import exceptions, urlresolvers
         from django.core.mail import mail_admins
-        from django.conf.settings import DEBUG, INTERNAL_IPS, ROOT_URLCONF
+        from django.conf.settings import DEBUG, INTERNAL_IPS, ROOT_URLCONF, URL_RESOLVER
 
         # Apply request middleware
         for middleware_method in self._request_middleware:
             response = middleware_method(request)
             if response:
                 return response
-
-        resolver = urlresolvers.RegexURLResolver(r'^/', ROOT_URLCONF)
         try:
+            dot = URL_RESOLVER.rindex('.')
+        except ValueError:
+            raise exceptions.ImproperlyConfigured, '%s isn\'t a resolver module' % URL_RESOLVER
+        ur_module, ur_classname = URL_RESOLVER[:dot], URL_RESOLVER[dot+1:]
+        try:
+            mod = __import__(ur_module, '', '', [''])
+        except ImportError, e:
+            raise exceptions.ImproperlyConfigured, 'Error importing urlresolver module %s: "%s"' % (ur_module, e)
+        try:
+                ur_class = getattr(mod, ur_classname)
+        except AttributeError:
+            raise exceptions.ImproperlyConfigured, 'Urlresolver module "%s" does not define a "%s" class' % (mw_module, mw_classname)
+        
+        resolver = ur_class(request, ROOT_URLCONF)
+        
+        try:
             callback, callback_args, callback_kwargs = resolver.resolve(path)
 
             # Apply view middleware
Index: views/debug.py
===================================================================
--- views/debug.py	(revision 1868)
+++ views/debug.py	(working copy)
@@ -135,11 +135,16 @@
         if not tried:
             # tried exists but is an empty list. The URLconf must've been empty.
             return empty_urlconf(request)
-
+    try:
+        host = exception.args[0]['host']
+    except:
+        host = False
+            
     t = Template(TECHNICAL_404_TEMPLATE)
     c = Context({
         'root_urlconf': settings.ROOT_URLCONF,
         'urlpatterns': tried,
+        'host': host,
         'reason': str(exception),
         'request': request,
         'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http",
@@ -547,12 +552,32 @@
     {% if urlpatterns %}
       <p>
       Using the URLconf defined in <code>{{ settings.ROOT_URLCONF }}</code>,
+      {% if host %}
+      Django tried these URL patterns with hostname <code>{{ host|escape }}</code>, in this order:
+      {% else %}
       Django tried these URL patterns, in this order:
+      {% endif %}
       </p>
       <ol>
-        {% for pattern in urlpatterns %}
-          <li>{{ pattern|escape }}</li>
-        {% endfor %}
+        {% if host %}
+            {% for pattern in urlpatterns %}
+                <li>{{ pattern.0|escape }}<br/>
+                {% if pattern.1 %}
+                    <ol>
+                    {% for match in pattern.1 %}
+                        <li>{{ match|escape}}</li>
+                    {% endfor %}
+                    </ol>
+                  {% else %}
+                  Hostname didn't match, or empty url pattern
+                  {% endif %}
+                  </li>
+            {% endfor %}
+        {% else %}
+            {% for pattern in urlpatterns %}
+              <li>{{ pattern|escape }}</li>
+            {% endfor %}
+        {% endif %}
       </ol>
       <p>The current URL, <code>{{ request.path }}</code>, didn't match any of these.</p>
     {% else %}
