Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Collapse
Uwyn Logo
  1. Home
  2. RIFE2
  3. RIFE2 Tips & Tricks

RIFE2 Tips & Tricks

Scheduled Pinned Locked Moved RIFE2
tipstricks
1 Posts 1 Posters 691 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ethauvinE Offline
    ethauvinE Offline
    ethauvin
    wrote on last edited by
    #1

    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();
        }
    }
    1 Reply Last reply
    1
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups