Skip to content

Commit 689ec78

Browse files
committed
Serve custom 404 page only on subdomain and cname requests
1 parent c32422a commit 689ec78

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

readthedocs/core/views/__init__.py

+18
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ def server_error_404(request, exception=None, template_name='404.html'): # pyli
131131
else:
132132
return response
133133

134+
# Try to serve custom 404 pages if it's a subdomain/cname
135+
if request.subdomain or request.cname:
136+
return server_error_404_subdomain(request, template_name)
137+
138+
# Return the default 404 page generated by Read the Docs
139+
r = render(request, template_name)
140+
r.status_code = 404
141+
return r
142+
143+
144+
def server_error_404_subdomain(request, template_name='404.html'):
145+
"""
146+
Handler for 404 pages on subdomains.
147+
148+
Check if the project associated has a custom ``404.html`` on it's project's
149+
root (default version) and serve it. Otherwise, fallback to the default
150+
``template_name`` rendered by Django.
151+
"""
134152
project, path = project_and_path_from_request(request, request.get_full_path())
135153
version_slug = project.get_default_version()
136154
version = project.versions.get(slug=version_slug)

0 commit comments

Comments
 (0)