简体   繁体   中英

Can Jekyll serve content based on a URL parameter?

I'm migrating a blog from WordPress to GitHub pages. In the logs for my site, I've noticed that there are many requests like this:

GET /wp/?feed=atom

This 301 redirects to the ATOM feed for the site.

I'd planned to use httrack to scrape my site and migrate all the static content. But this presents a problem. Is there any way to replicate the /wp/?foo=bar redirects using Jekyll?

You can use Jekyll redirect_from plugin which is one of the rare plugin that can be used on github pages.

The only problem is that yoursite.github.io/wp/?foo=bar from the server point of view is yoursite.github.io/wp/index.php?foo=bar . So, any ?foo=bar is resolved to the same file.

I you have only your xml feed to redirect, this does the trick :

---
layout: null
redirect_from:
  - /wp/
---
content ...

If you have multiple files to redirect, you will have to switch to a javascript solution from a wp/index.html file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM