Catch-all URL rewrite on Google App Engine (Java)

耗尽温柔 提交于 2019-12-06 07:57:41

What about the following rule:

<rule>
   <from>^/([\w-]+)$</from>
   <to last="true">/vote.jsp?id=$1</to>
</rule>

Where [\w-]+ is at least one any word character (letter, number, underscore) including - (dash character). You use ^ and $ to anchor beginning and end of checked text.


UrlRewriteFilter documentation says

When executing a rule the filter will (very simplified) loop over all rules and for each do something like this psuedo code:

Pattern.compile(<from> element); pattern.matcher(request url);
matcher.replaceAll(<to> element); 
if ( <condition> elements match && matcher.find() ) {
    handle <set> elements (if any)
    execute <run> elements (if any)
    perform <to> element (if any) 
}

That's why you have to use beginning (^) and end ($) string regular expression anchors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!