Repository: mkdocs/mkdocs

Issue:
Broken links/css in readthedocs 404 page 
The [404.html](https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/readthedocs/404.html) added in 0.17.0 seems to have broken links and css ([failing CI build](https://travis-ci.org/opensciencegrid/docs/builds/290469999?utm_source=github_status&utm_medium=notification)). The links in the generated `404.html` file all start with a `docs/...` prefix but when I inspect the `site` dir after a `mkdocs build`, there is no `docs` directory.


Discussion:
Hmm, its working fine for me (see [mkdocs.org][1]). I checked the readthedocs theme locally, and it works fine also. So I looked at your project.

Then I noticed that you have `site_url: https://opensciencegrid.github.io/docs` set in your [config file][2]. As the 404 page could be shown for any URL, it can't use relative URLS. Therefore, it uses `site_url` to derive an absolute URL. In your case, it takes `/docs` from the `site_url` setting and prepends it to the URL of each link on the page. Of course, when running the dev server locally, that shouldn't apply.

At the time that we implemented the absolute URLs that way, the dev server didn't have support for returning a 404 page (just a simple plain-text message), so we weren't concerned that it didn't work there as it does on the production server. Since then, we got 404 support added to the dev server and presumably forgot about that detail.

Thanks for the report. We'll need to fix this. However, be aware that while your patch (via a custom 404 template) appears to resolve the problem in the dev server, it will have broken things on the production server if/when you deploy it. I would recommend removing it and enduring the broken dev server until we fix this in 0.17.1 (I hope). 

[1]: http://www.mkdocs.org/foo
[2]: https://github.com/opensciencegrid/docs/blob/master/mkdocs.yml#L2
Thanks for the quick reply! The custom 404 seems to be working in production (https://opensciencegrid.github.io/docs/site-planning/s) so we'll probably just keep things this way until this is fixed.
@brianhlin was the default 404 page broken for you in production or only on the dev server? I assume only on the dev server, but if not, then we have a more serious problem.

For future reference (for myself mostly) , a detailed explanation of the relative/absolute problem is in [this comment][1]. #1039 provided the fix for error pages with an acknowledgement that it doesn't work on the dev server. And we added error page support to the dev server in #1141 (where we forgot to address this issue).

[1]: https://github.com/mkdocs/mkdocs/issues/77#issuecomment-242777289
I hadn't bothered to push the change to production, previously. I tested it on my [own fork](https://brianhlin.github.io/docs/s) and it looks like you're right, it works in production.

Resolving patch:
diff --git a/mkdocs/commands/serve.py b/mkdocs/commands/serve.py
--- a/mkdocs/commands/serve.py
+++ b/mkdocs/commands/serve.py
@@ -103,7 +103,10 @@ def builder():
             theme=theme,
             theme_dir=theme_dir
         )
+        # Override a few config settings after validation
         config['site_dir'] = tempdir
+        config['site_url'] = 'http://{0}/'.format(config['dev_addr'])
+
         live_server = livereload in ['dirty', 'livereload']
         dirty = livereload == 'dirty'
         build(config, live_server=live_server, dirty=dirty)


Test patch: