jekyll / jekyll-redirect-from

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

`redirect_from` is adding `site.baseurl` to `site.url` (Duplicates the baseurl on Github Pages) #257

Closed David00 closed 1 year ago

David00 commented 1 year ago

Hi, I have a site hosted on Github pages, and redirect_from is appending the site.base_url after the site.url.

I'm simply attempting to redirect requests that go to /docs/latest/page.md to /docs/v0.3.0/page.md.

My site's baseurl is /rpi-power-monitor, and the site.url is https://david00.github.io/rpi-power-monitor. When I use redirect_from, I end up getting redirected to https://david00.github.io/rpi-power-monitor/rpi-power-monitor.

I've setup a demo of exactly what I mean, which contains some details about the page's front matter, the values of site.url and site.baseurl, and a few redirect_from values that I've tried:

https://david00.github.io/rpi-power-monitor/docs/v0.3.0/test.html

If you want to see my site's _config.yml and Gemfile, they are here in the docs branch: https://github.com/David00/rpi-power-monitor/tree/docs

Please let me know if you need any more info!

Thank you.

ashmaroli commented 1 year ago

Technically, stitching site.url with site.baseurl is expected and by design because that is what Jekyll considers as leading components of an absolute URL.

However, the duplication of the /rpi-power-monitor in your case is due to configuration mismatch.

GitHub Pages probably sets the --baseurl Jekyll CLI switch under the hood which is evident in the /docs/v0.3.0/test.html render (in contrast to what is in your _config.yml). To rectify, edit your config file to have (which is actually the correct way):

url: "https://david00.github.io"
baseurl: "/rpi-power-monitor"
David00 commented 1 year ago

That worked!!

That should have been so obvious to me... but it wasn't. I actually tried the opposite edit of setting baseurl: "", but that broke all of the styling.

Thank you so much for taking a look and providing context and a solution!