jekyll / jekyll-redirect-from

:twisted_rightwards_arrows: Seamlessly specify multiple redirections URLs for your pages and posts.
MIT License
782 stars 114 forks source link

redirect_to does not use baseurl #130

Closed bcardiff closed 7 years ago

bcardiff commented 7 years ago

redirect_from use baseurl to build the url to use in the redirection. I think the same should happen with redirect_to so the redirect configuration does not depend how the site is hosted.

I created a minimal repo https://github.com/bcardiff/issue-redirect-to which is hosted as https://bcardiff.github.io/issue-redirect-to/ that shows lack of symmetry between these two settings.

Maybe I am doing something obviously wrong, in that case I appreciate some guidance.

# request real content handled by a .md
# OK, the content is returned.
$ curl https://bcardiff.github.io/issue-redirect-to/real-source.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>This is real</title>
    <link href="https://bcardiff.github.io/issue-redirect-to/assets/css/style.css?v=dda4ded1c1234502b3b391aa2e9ac25b5f3d0eea" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <h1 id="this-is-real">This is real</h1>

    </div>
  </body>
</html>

# request a path handled by redirect_from in the same .md file as the previous step
# OK, the redirect goes to /issue-redirect-to/real-source.html
$ curl https://bcardiff.github.io/issue-redirect-to/fake-source.html
<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
<title>Redirecting…</title>
<link rel="canonical" href="/issue-redirect-to/real-source.html">
<meta http-equiv="refresh" content="0; url=/issue-redirect-to/real-source.html">
<h1>Redirecting…</h1>
<a href="/issue-redirect-to/real-source.html">Click here if you are not redirected.</a>
<script>location="/issue-redirect-to/real-source.html"</script>
</html>

# request a path handled by redirect_to in another .md file
# :-(, the redirect goes to /real-source.html instead of /issue-redirect-to/real-source.html
$ curl https://bcardiff.github.io/issue-redirect-to/other-fake-source.html
<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
<title>Redirecting…</title>
<link rel="canonical" href="/real-source.html">
<meta http-equiv="refresh" content="0; url=/real-source.html">
<h1>Redirecting…</h1>
<a href="/real-source.html">Click here if you are not redirected.</a>
<script>location="/real-source.html"</script>
</html>

updated output after applying https://github.com/jekyll/jekyll-redirect-from/issues/130#issuecomment-268593451

parkr commented 7 years ago

baseurl is just a path, not a full URL. That should be:

url: https://bcardiff.github.io
baseurl: /issue-redirect-to

Check out this for more details: https://byparker.com/blog/2014/clearing-up-confusion-around-baseurl/

bcardiff commented 7 years ago

Thanks @parkr that tidy up the things regarding the 2nd request (redirect_from), but not the 3rd request (redirect_to). I've just updated the issue description so the output is more clear.

benbalter commented 7 years ago

Fixed via #131.