Re: automatically adding trailing slashes to url's that “need” slash

Splash Forums PrettyFaces Users automatically adding trailing slashes to url's that "need" slash Re: automatically adding trailing slashes to url's that “need” slash

#21717

Hey Serkan,

I think there are basically two ways to achieve this:

First you could try to build the correct regular expression for the usecase. But this will be very difficult. What you will probably need is a negative lookahead which is a very advance regular expression feature. Take a look at this page for some details on this:

Guide to Regular Expressions in Java (Part 2)

You could also search this forum for “lookahead” and you will find some interesting posts. To test your regular expressions I recommend to take a look at this site:

http://myregexp.com/

BTW: You won’t have to implement the “it doesn’t already have a trailing slash” check in the regular expression because “trailingSlash” will do this for you.

The second option to implement this behavior is to write a custom rewrite processor. Just use a rewrite rule that matches URLs and implement the behavior yourself:

<rewrite processor="com.example.myapp.MyProcessor" />

Now just implement the Processor interface and do whatever you want with the URL! :)

See this part of the documentation for details:

http://ocpsoft.com/docs/prettyfaces/3.3.2/en-US/html/inbound_rewriting.html

I hope this helps! :)

Christian