Skip to content

Commit

Permalink
BUG: Update sphinx custom 404 page to handle redirect of vX.Y URL wit…
Browse files Browse the repository at this point in the history
…hout slash

This commit adds a javascript redirect to handle the redirection of page
like https://slicer.readthedocs.io/en/v5.0 to https://slicer.readthedocs.io/en/v5.0/
and workaround limitation documented in readthedocs/readthedocs.org#9507

Indeed, despite of adding the following "Exact Redirect" to the readthedocs
configuration:

```
/en/v5.0 -> /en/5.0
/en/v5.0/$rest -> /en/5.0/
```
, specifying https://slicer.readthedocs.io/en/v5.0 doesn't redirect to
https://slicer.readthedocs.io/en/5.0
  • Loading branch information
jcfr committed Aug 16, 2022
1 parent 0fe4d8f commit 1ba81e9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@
# https://github.com/readthedocs/sphinx-notfound-page
notfound_context = {
'title': 'Page Not Found',
'body': '''
'body': r'''
<script type="text/javascript">
// Workaround https://github.com/readthedocs/readthedocs.org/issues/9507
const regex = /^https:\/\/slicer\.readthedocs\.io\/\w+\/v\d\.\d$/;
if (regex.test(window.location)) {
window.location.replace(window.location + "/");
}
</script>
<h1>Page Not Found</h1>
<p>Sorry, we couldn't find that page.</p>
<p>Try using the search box or go to the homepage.</p>
Expand Down

0 comments on commit 1ba81e9

Please sign in to comment.