When converting an existing website, you will most likely want to redirect old URLs to the new ones. RIFE2 makes it pretty simple. For example, to redirect:
https://example.com/news/2023/09/11
to
https://example.com/search?year=2023&month=09&day=11
You can easily convert the path info into parameters, by doing something like:
public class ExampleSite extends Site {
//...
private void redirectMoved(Context c, String url) {
c.setStatus(301);
c.addHeader("Location", url);
}
private void setRedirects() {
//..
get("/news", PathInfoHandling.MAP(
m -> m.p("year"),
m -> m.p("year").s().p("month"),
m -> m.p("year").s().p("month").s().p("day")),
c -> redirectMoved(c, c.urlFor(searchUrl).params(c.parameters()).toString()));
}
@Override
public void setup() {
//..
setRedirects();
}
}