<rewrite trailingSlash="append" toCase="lowercase" redirect="301"/> <rewrite match="/foo" substitute="/bar" redirect="301"/>
<rewrite toCase="lowercase" redirect="chain" />
<rewrite match="/foo" trailingSlash="append" toCase="lowercase" /><rewrite match="/foo/(/w+)/" substitute="/bar/$1/" /><rewrite match="/foo/(/w+)/" url="http://example.com/$1/" />The table below outlines each of the individual rewrite-rule options:
Option Allowed values Usage inbound true/false (Default: true) Enable or disable inbound URL rewriting for this rule. Setting this value to false means that this rule will be ignored on incoming requests. match a regex (Optional) Describes, via a regular expression pattern, when this 'rewrite' rule should trigger on an inbound or outbound URL. If empty, this rule will match all URLs. outbound true/false (Default: true) Enable or disable outbound URL rewriting for this rule. If enabled, any matching links encoded using HttpServletResponse.encodeURL() will be rewritten according to the rules specified. processor qualified class name (Optional.) Specify a custom processor class to perform more complex, custom URL-rewriting. This class must implement the interface: 'com.ocpsoft.pretty.faces.rewrite.Processor' public class CustomClassProcessor implements Processor { public static final String RESULT = "I PROCESSED!"; public String process(final RewriteRule rewrite, final String url) { return RESULT; } }redirect 301, 302, chain (Default: 301) Specifies which type of redirect should be issued when this rule triggers. If 'chain' is specified, a Servlet forward will be issued to the new URL instead of a redirect. substitute lifecycle (Optional.) The regular expression substitution value of the "match" attribute. This effectively enables a "search and replace" functionality. Regular expression back-references to the match="..." attribute are supported in the URL, so using '$' and '/' characters may change the value of the result. See Rewriting URLs that match a specific pattern, for more details. toCase uppercase, lowercase, ignore (Default: ignore) Change the entire URL (excluding context-path and query- parameters) to 'UPPERCASE' or 'lowercase'. trailingSlash append, remove, ignore (Default: ignore) Control whether trailing slashes on a URL should be appended if missing, or removed if present. url a well-formed URL (Optional.) Specify an well-formed URL to replace the current URL. This will overwrite the context-path and query-parameters. This attribute should usually be combined with redirect="301" (default), which is recommended to prevent adverse SEO effects, loss of page- rank.) Note: You must provide a fully qualified URL, including scheme (such as 'http://", 'ftp://', 'mailto:'). Regular expression back-references to the match="..." attribute are supported in the URL, so using '$' and '/' characters may change the value of the result. See Rewriting URLs that match a specific pattern, for more details. Rewriting URLs in JSF views
<url-mapping id="viewCategory"> <pattern value="/store/#{ cat : bean.category }/" /> <view-id>/faces/shop/store.jsf</view-id> </url-mapping><h:link outcome="/faces/shop/store.jsf" value="View category: Shoes> <f:param name="cat" value="shoes" /> <f:param name="lang" value="en_US" /> </h:link>或者<h:link outcome="pretty:viewCategory" value="View category: Shoes> <f:param name="cat" value="shoes" /> <f:param name="lang" value="en_US" /> </h:link>得到结果URL/store/shoes/?lang=en_US<pretty:link>
<url-mapping id="viewItem"> <pattern value="/store/#{ cat : bean.category }/#{ iid : bean.itemId }/" /> <view-id>/faces/shop/item.jsf</view-id> <action>#{bean.loadItem}</action> </url-mapping><%@ taglib prefix="pretty" uri="http://ocpsoft.com/prettyfaces" %> <pretty:link mappingId="viewItem"> <f:param value="#{item.category}" /> <f:param value="#{item.id}" /> View Item. (This is Link Text) </pretty:link>结果URL/store/shoes/24