diff --git django/middleware/common.py django/middleware/common.py
index b2c97c6..3090588 100644
--- django/middleware/common.py
+++ django/middleware/common.py
@@ -53,8 +53,9 @@ class CommonMiddleware(object):
         # Append a slash if APPEND_SLASH is set and the URL doesn't have a
         # trailing slash and there is no pattern for the current path
         if settings.APPEND_SLASH and (not old_url[1].endswith('/')):
-            if (not _is_valid_path(request.path_info) and
-                    _is_valid_path("%s/" % request.path_info)):
+            urlconf = getattr(request, 'urlconf', None)
+            if (not _is_valid_path(request.path_info, urlconf) and
+                    _is_valid_path("%s/" % request.path_info, urlconf)):
                 new_url[1] = new_url[1] + '/'
                 if settings.DEBUG and request.method == 'POST':
                     raise RuntimeError, (""
@@ -130,7 +131,7 @@ def _is_internal_request(domain, referer):
     # Different subdomains are treated as different domains.
     return referer is not None and re.match("^https?://%s/" % re.escape(domain), referer)
 
-def _is_valid_path(path):
+def _is_valid_path(path, urlconf=None):
     """
     Returns True if the given path resolves against the default URL resolver,
     False otherwise.
@@ -139,7 +140,7 @@ def _is_valid_path(path):
     easier, avoiding unnecessarily indented try...except blocks.
     """
     try:
-        urlresolvers.resolve(path)
+        urlresolvers.resolve(path, urlconf)
         return True
     except urlresolvers.Resolver404:
         return False
diff --git tests/regressiontests/middleware/extra_urls.py tests/regressiontests/middleware/extra_urls.py
new file mode 100644
index 0000000..b2a8902
--- /dev/null
+++ tests/regressiontests/middleware/extra_urls.py
@@ -0,0 +1,7 @@
+from django.conf.urls.defaults import patterns
+
+urlpatterns = patterns('',
+    (r'^middleware/customurlconf/noslash$', 'view'),
+    (r'^middleware/customurlconf/slash/$', 'view'),
+    (r'^middleware/customurlconf/needsquoting#/$', 'view'),
+)
diff --git tests/regressiontests/middleware/tests.py tests/regressiontests/middleware/tests.py
index b7e830a..789bb7f 100644
--- tests/regressiontests/middleware/tests.py
+++ tests/regressiontests/middleware/tests.py
@@ -125,3 +125,120 @@ class CommonMiddlewareTest(TestCase):
         self.assertEquals(r.status_code, 301)
         self.assertEquals(r['Location'],
                           'http://www.testserver/middleware/slash/')
+   
+
+    #The following tests  examine expected behavior given a custom urlconf that
+    #overrides the default one through the request object.
+
+    def test_append_slash_have_slash_custom_urlconf(self):
+      """
+      Tests that URLs with slashes go unmolested.
+      """
+      settings.APPEND_SLASH = True
+      request = self._get_request('customurlconf/slash/')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      self.assertEquals(CommonMiddleware().process_request(request), None)
+
+    def test_append_slash_slashless_resource_custom_urlconf(self):
+      """
+      Tests that matches to explicit slashless URLs go unmolested.
+      """
+      settings.APPEND_SLASH = True
+      request = self._get_request('customurlconf/noslash')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      self.assertEquals(CommonMiddleware().process_request(request), None)
+
+    def test_append_slash_slashless_unknown_custom_urlconf(self):
+      """
+      Tests that APPEND_SLASH doesn't redirect to unknown resources.
+      """
+      settings.APPEND_SLASH = True
+      request = self._get_request('customurlconf/unknown')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      self.assertEquals(CommonMiddleware().process_request(request), None)
+
+    def test_append_slash_redirect_custom_urlconf(self):
+      """
+      Tests that APPEND_SLASH redirects slashless URLs to a valid pattern.
+      """
+      settings.APPEND_SLASH = True
+      request = self._get_request('customurlconf/slash')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      r = CommonMiddleware().process_request(request)
+      self.assertEquals(r.status_code, 301)
+      self.assertEquals(r['Location'], 'http://testserver/middleware/customurlconf/slash/')
+
+    def test_append_slash_no_redirect_on_POST_in_DEBUG_custom_urlconf(self):
+      """
+      Tests that while in debug mode, an exception is raised with a warning
+      when a failed attempt is made to POST to an URL which would normally be
+      redirected to a slashed version.
+      """
+      settings.APPEND_SLASH = True
+      settings.DEBUG = True
+      request = self._get_request('customurlconf/slash')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      request.method = 'POST'
+      self.assertRaises(
+          RuntimeError,
+          CommonMiddleware().process_request,
+          request)
+      try:
+          CommonMiddleware().process_request(request)
+      except RuntimeError, e:
+          self.failUnless('end in a slash' in str(e))
+      settings.DEBUG = False
+
+    def test_append_slash_disabled_custom_urlconf(self):
+      """
+      Tests disabling append slash functionality.
+      """
+      settings.APPEND_SLASH = False
+      request = self._get_request('customurlconf/slash')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      self.assertEquals(CommonMiddleware().process_request(request), None)
+
+    def test_append_slash_quoted_custom_urlconf(self):
+      """
+      Tests that URLs which require quoting are redirected to their slash
+      version ok.
+      """
+      settings.APPEND_SLASH = True
+      request = self._get_request('customurlconf/needsquoting#')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      r = CommonMiddleware().process_request(request)
+      self.assertEquals(r.status_code, 301)
+      self.assertEquals(
+          r['Location'],
+          'http://testserver/middleware/customurlconf/needsquoting%23/')
+
+    def test_prepend_www_custom_urlconf(self):
+      settings.PREPEND_WWW = True
+      settings.APPEND_SLASH = False
+      request = self._get_request('customurlconf/path/')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      r = CommonMiddleware().process_request(request)
+      self.assertEquals(r.status_code, 301)
+      self.assertEquals(
+          r['Location'],
+          'http://www.testserver/middleware/customurlconf/path/')
+
+    def test_prepend_www_append_slash_have_slash_custom_urlconf(self):
+      settings.PREPEND_WWW = True
+      settings.APPEND_SLASH = True
+      request = self._get_request('customurlconf/slash/')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      r = CommonMiddleware().process_request(request)
+      self.assertEquals(r.status_code, 301)
+      self.assertEquals(r['Location'],
+                        'http://www.testserver/middleware/customurlconf/slash/')
+
+    def test_prepend_www_append_slash_slashless_custom_urlconf(self):
+      settings.PREPEND_WWW = True
+      settings.APPEND_SLASH = True
+      request = self._get_request('customurlconf/slash')
+      request.urlconf = 'regressiontests.middleware.extra_urls'
+      r = CommonMiddleware().process_request(request)
+      self.assertEquals(r.status_code, 301)
+      self.assertEquals(r['Location'],
+                        'http://www.testserver/middleware/customurlconf/slash/')
