Matching groups in rules

Splash Forums Rewrite Users Matching groups in rules

This topic contains 3 replies, has 3 voices, and was last updated by  Lincoln Baxter III 3 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #23769

    Will Durman
    Participant

    I have this rule declared:

    .addRule(
    Join.path("/products/{id}")
    .to("/public/content/products/productView.jsf"))

    However, I would like to, by regular expression, only include a portion of the {id} parameter. I already have the regular expression pattern figured it out.Is it possible to manipulate the parameter in this way?

    For example, if the incoming URL is:
    /products/really-long-description-B100
    Then I would like the “joined” URLto be:
    /public/content/products/productView.jsf?id=B100

    #23770

    You could simply split up the parameter into two distinct ones. Something like this:

    .addRule(Join.path("/products/{name}-{id}").to("/public/content/products/productView.jsf"))
    .where("name").matches("[\\w\\-]+")
    .where("id").matches("B\\d+")
    #23790

    Will Durman
    Participant

    Excellent suggestion! This is the rule I ended up using, with slightly different regex:

    
    .addRule(
       Join.path("/products/{productSlug}-{productGroupName}").to("/public/content/jewelry/productView.jsf"))
       .perform(Log.message(Logger.Level.INFO, "Joining on /products/{productSlug} aaand {productGroupName}"))
       .where("productSlug").matches("[\\w\\-]+")
       .where("productGroupName").matches(".*$")
    
    #23833

    Very nice! Glad this got you up and running! Nice addition of “Log” 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Comments are closed.