-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom 404 for subdomains #353
Comments
Yea, I've thought a little about how to improve the 404 pages. I think also Can you explain exactly what you want in the page? Basically just more Cheers, On Mon, Mar 11, 2013 at 6:49 PM, bdarnell [email protected] wrote:
Eric Holscher |
It would be nice if the page could be branded as "Tornado" instead of "Read the Docs", and have the most prominent link on the page go to www.tornadoweb.org/ (the link at the top goes to the right place, but it looks like you're on the wrong site now). If I could upload my own html file that would be ideal (and then assuming I can run javascript I could do my own redirects from /documentation/ to /en/branch2.4/). |
It would be pretty simple to handle smarter 404 logic, by adding it to this function: https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/core/views.py#L437 -- It would be nice to try and figure out a proper page to redirect to automatically, or at least give some possible pages they might want in the response as well. |
It would be pretty nice if it was possible just to redirect to the projects custom 404.html if it exists. That way I can just create a 404.rst and add something to it that at least keeps the user on a page that looks like the rest of the site. |
Thinking about this now, it should be pretty simple to do. We can look for a |
Looked into this. The 404.html at the root has relative URL's for the media files, so we can't use it for a generic 404 page. Need to either post-process the 404.html to make the media links absolute, or proxy the page somehow in a way that doesn't break things. |
I think the best option would be to build a Sphinx extension that inserts a 404.rst if it doesn't exist, and then rewrites the linked media files on output. I'd be happy to integrate this into RTD if someone writes it :) |
I wrote an initial implementation of this that needs some cleanup to deploy: def html_collect_pages(app):
return [('404', {'body': '<h1>Page not found</h1>\n\nThanks for trying.'}, 'page.html')]
def finalize_media(app, pagename, templatename, context, doctree):
""" Point media files at our media server. """
def pathto(otheruri, resource=False, baseuri='/'):
"Hack pathto to display absolute URL's"
if resource and '://' in otheruri:
# allow non-local resources given by scheme
return otheruri
elif not resource:
otheruri = app.builder.get_target_uri(otheruri)
if otheruri and otheruri[0] != '/':
otheruri = '/' + otheruri
uri = otheruri or '#'
return uri
if pagename == '404':
context['pathto'] = pathto
def setup(app):
app.connect('html-collect-pages', html_collect_pages)
app.connect('html-page-context', finalize_media) |
It will also need updates to our nginx 404 settings, but getting the 404 pages working at any URL is the first step. |
Adding some context here, this is what GitHub does: https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/ |
We need to consider that we host docs per version, I guess we could have this:
And we could fallback to the own rtd 404 page if users don't have one. |
Some context about our current setup
Considerations
Idea of a potential solutionFrom Read the Docs server/config side, at step 3) of our current setup, we could check if the project has already a
From the user side, a plain HTML (with hardcoded URLs) has to be provided at If we could write this extension I think it would be good UX from the user perspective.
|
I worked on this and I created the Sphinx extension ( You can see a live example under Read the Docs: https://test-builds.readthedocs.io/en/custom-404-page/
If you check the source code of the 404 page served by the example, you will see that all the links are absolute. Example, <link rel="stylesheet" href="/en/latest/_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="/en/latest/_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="/en/latest/genindex.html" />
<link rel="search" title="Search" href="/en/latest/search.html" /> So, it seems the only missing piece here is to modify the RTD source code to find this file and serve it if it does exists. |
The PR was merged and deployed. I'd like to hear back from users that wanted to have a custom 404 if you were able to configure it properly: dropping a |
Works great! |
@humitos We created a custom 404.rst in root and let ReadtheDocs render the pages. All paths that start like /en/latest/pagethatdoesnotexist show the 404.html perfectly in the theme but when that /en/latest part is missing the 404.html gets shown but the css is broken and the theme is missing. Any hints how to fix that? :) |
@Solosneros yes, you have to use absolute links to make the resources load properly. This is the most important part. You have 2 options to achieve this:
|
@humitos thanks for the fast reply. I tried using your extension and the build keeps failing. Is the extension automatically included in ReadtheDocs.org?
|
You probably need to add it to a |
@Solosneros no, you have to install it as any other dependency (https://docs.readthedocs.io/en/latest/guides/specifying-dependencies.html) as @kdheepak mentioned. |
@humitos thanks, it works now :) |
I just moved www.tornadoweb.org to readthedocs using a CNAME. This broke some links (which is not ideal but I can live with it), but the resulting 404 page is not helpful (e.g. www.tornadoweb.org/documentation/). The 404 page for a recognized subdomain/cname should include a link to that hostname's root. (of course, custom redirects for my domain would be awesome too)
The text was updated successfully, but these errors were encountered: