Return 404 at SubdomainMiddleware level if project doesn't exist
While deploying .com we found that `SubdomainMiddleware` doesn't check the existence of the project that it's injecting at `request.slug`.

So, any middleware that relies on this to do some extra work, will probably do something like `Project.objects.get(slug=request.slug)` and will fail.

We workarounded it by adding `try/except` block in the middleware that uses this, but we should probably just raise a 404 inside the `SubdomainMiddleware` itself instead of continue with the flow.

Code: https://github.com/rtfd/readthedocs.org/blob/74bbb3ac23b6b06a70517bc1b301961db6821e32/readthedocs/core/middleware.py#L72
diff --git a/readthedocs/core/middleware.py b/readthedocs/core/middleware.py
index 5123ccee6..7dce74588 100644
--- a/readthedocs/core/middleware.py
+++ b/readthedocs/core/middleware.py
@@ -69,6 +69,8 @@ class SubdomainMiddleware(object):
                 # Support ports during local dev
                 public_domain in host or public_domain in full_host
             ):
+                if not Project.objects.filter(slug=subdomain).exists():
+                    raise Http404(_('Project not found'))
                 request.subdomain = True
                 request.slug = subdomain
                 request.urlconf = SUBDOMAIN_URLCONF
diff --git a/readthedocs/rtd_tests/tests/test_middleware.py b/readthedocs/rtd_tests/tests/test_middleware.py
index 444a4f2d1..574708552 100644
--- a/readthedocs/rtd_tests/tests/test_middleware.py
+++ b/readthedocs/rtd_tests/tests/test_middleware.py
@@ -47,6 +47,13 @@ class MiddlewareTests(TestCase):
         self.assertEqual(request.urlconf, self.urlconf_subdomain)
         self.assertEqual(request.slug, 'pip')
 
+    @override_settings(PRODUCTION_DOMAIN='readthedocs.org')
+    def test_wrong_subdomain(self):
+        http_host = 'xyz-wrong-sub-domain-xyz.readthedocs.org'
+        request = self.factory.get(self.url, HTTP_HOST=http_host)
+        with self.assertRaises(Http404):
+            self.middleware.process_request(request)
+
     @override_settings(PRODUCTION_DOMAIN='readthedocs.org')
     def test_restore_urlconf_after_request(self):
         """
['readthedocs/core/middleware.py', 'readthedocs/rtd_tests/tests/test_middleware.py']