2

I read GitHub pages documentation for enabling redirects on GitHub Pages using the jekyll-redirect-from plugin. I was able to redirect from one page to another, but I have some different requirements. I need to redirect all pages from a starting url to another.

These URLs

  • www.example.com/abc/def
  • www.example.com/abc/xyz

should be redirected to

  • www.example.com
kalehmann
  • 4,821
  • 6
  • 26
  • 36
pandafy
  • 184
  • 13

1 Answers1

2

As stated in the documentation for the plugin, you can add specify multiple urls for the redirect_from key.

For example create a index.md file with:

---
title: index
redirect_from:
  - /abc/def/
  - /abc/xyz/
---

## Hello, world!

and a _config.yml with:

title: Redirection test

markdown: kramdown
plugins:
  - jekyll-feed
  - jekyll-redirect-from

Now both /abc/def and /abc/xyz will redirect to your index page.

kalehmann
  • 4,821
  • 6
  • 26
  • 36
  • I need to redirect a family of urls not just two. – pandafy Mar 14 '20 at 16:38
  • @TheOneAboveAll You mean redirection all urls, that start with `/abc/*` ? – kalehmann Mar 14 '20 at 17:08
  • Yes, I want to achieve redirection for a url pattern @kalehmann – pandafy Mar 14 '20 at 20:31
  • 1
    @TheOneAboveAll As far as I know, this is not possible using Jekyll and GitHub pages. The closest you could achieve with GitHub pages would be [creating a custom 404 page](https://help.github.com/en/github/working-with-github-pages/creating-a-custom-404-page-for-your-github-pages-site) with [a redirect](https://stackoverflow.com/questions/5411538/redirect-from-an-html-page). This would allow you to redirect all nonexisting pages to one page of your choice. – kalehmann Mar 14 '20 at 21:11