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 e2def00
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
notfound_context = {
'title': 'Page Not Found',
'body': '''
<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 e2def00

Please sign in to comment.