mkdocs / mkdocs-redirects

Open source plugin for Mkdocs page redirects
MIT License
176 stars 25 forks source link

Redirects don't work locally #17

Closed wilhelmer closed 3 years ago

wilhelmer commented 3 years ago

When the HTML output files are accessed locally (file:// protocol), the redirects don't work.

This is because of the leading slash in the redirect target.

Tested in Firefox and Chrome.

mkdocs.yml

use_directory_urls: false
plugins:
    - redirects:
        redirect_maps:
            'old.md': 'new.md'

old.html

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Redirecting...</title>
    <link rel="canonical" href="/new.html">
    <meta name="robots" content="noindex">
    <script>var anchor = window.location.hash.substr(1); location.href = "/new.html" + (anchor ? "#" + anchor : "")</script>
    <meta http-equiv="refresh" content="0; url=/new.html">
</head>

<body>
    Redirecting...
</body>

</html>

Solution

If I manually replace /new.html by new.html, everything works fine, both locally and on the web, and both in Chrome and Firefox.