Parameter that matches over slashes

Splash Forums Rewrite Users Parameter that matches over slashes

This topic contains 3 replies, has 3 voices, and was last updated by  Christian Kaltepoth 2 years, 6 months ago.

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

    defuchs
    Participant

    Hi there

    Is it possible to match a parameter over slashes?

    I want to do this:

    from:
    /a.xml
    /a/b.xml
    /a/b/c.xml
    /a/b/c/d.xml

    to:
    /a.html
    /a/b.html
    /a/b/c.html
    /a/b/c/d.html

    MUST be a redirect.

    config.addRule().when( Direction.isInbound().and( Path.matches(“/{whatever}.xml”) ) ).perform( Redirect.temporary( “/{whatever}.html” )

    this works for all:
    abcd.xml

    but not
    if there is a “/” in the path it’s not matching anymore.

    Any solutions?

    #25451

    Sure, just configure the parameter like this:

    .addRule()
    .when( Direction.isInbound().and( Path.matches("/{whatever}.xml") ) )
    .perform( Redirect.temporary( "/{whatever}.html" )
    .where("whatever").matches(".*")
    
    #25761

    cumanji
    Participant

    i want to do the same but without extension :
    from:
    /a
    /a/b
    /a/b/c
    /a/b/c/d

    to:
    /a.xhtml
    /a/b.xhtml
    /a/b/c.xhtml
    /a/b/c/d.xhtml

    Can i do that?

    #25770

    Do you want to redirect or do you want to use a join? For a join it would look like this:

    .addRule( Join.path("/{whatever}").to("{whatever}.xhtml") )
    .where("whatever").matches(".+")
    

    However, you have to be very careful with such rules, because they will also match CSS resources and images which typically means that your site will break.

    My recommendation is to either use a number of specific joins to capture individual pages like this:

    .addRule( Join.path("/login").to("/faces/login.xhtml") )
    

    Or fine tune your regular expressions so that images and CSS files do not match. You could for example do this by excluding . from the allowed characters.

    .addRule( Join.path("/{something}").to("/{something}.xhtml") )
    .where("something").matches("[^\\.]+");
    

    This would for example match /login and /some/where but NOT /styles/default.css.

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

You must be logged in to reply to this topic.

Comments are closed.