Can Jekyll serve content based on a URL parameter?

萝らか妹 提交于 2020-01-05 17:51:30

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26374707/can-jekyll-serve-content-based-on-a-url-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!