7.5. URL rewriting with page parameters
Rewriting occurs based on patterns found for views in
pages.xml
. Seam URL rewriting performs both incoming and outgoing URL rewriting based on the same pattern. A simple pattern for this process is:
<page view-id="/home.xhtml"> <rewrite pattern="/home" /> </page>
In this case, any incoming request for
/home
will be sent to /home.xhtml
. Any link generated that would normally point to /home.seam
will instead be rewritten as /home
. Rewrite patterns only match the portion of the URL before the query parameters, so /home.seam?conversationId=13
and /home.seam?color=red
will both be matched by this rewrite rule.
Rewrite rules can take query paramters into consideration, as shown with the following rules.
<page view-id="/home.xhtml"> <rewrite pattern="/home/{color}" /> <rewrite pattern="/home" /> </page>
In this case, an incoming request for
/home/red
will be served as if it were a request for /home.seam?color=red
. Similarly, if color is a page parameter, an outgoing URL that would normally show as /home.seam?color=blue
would instead be output as /home/blue
. Rules are processed in order, so it is important to list more specific rules before more general rules.
Default Seam query parameters can also be mapped with URL rewriting, further concealing Seam's fingerprints. In the following example,
/search.seam?conversationId=13
would be written as /search-13
.
<page view-id="/search.xhtml"> <rewrite pattern="/search-{conversationId}" /> <rewrite pattern="/search" /> </page>
Seam URL rewriting provides simple, bidirectional rewriting on a per-view basis. For more complex rewriting rules that cover non-Seam components, Seam applications can continue to use the
org.tuckey.URLRewriteFilter
, or apply rewriting rules at the web server.
To use URL rewriting, the Seam rewrite filter must be enabled. Rewrite filter configuration is discussed in Section 28.1.4.3, “URL rewriting”.