我正在使用带有Java/Jersey REST API的AngularJS 1.3 webapp.我终于让html5mode使用了Tuckey UrlRewriteFilter,这样就像localhost:8080 /#/ page这样的东西现在只是localhost:8080/page.但是,我似乎无法获得像localhost这样更复杂的东西:8080/mypage/category/subcategory/item正常工作.在单个浏览器选项卡中,此URL将在html5mode中加载,但如果我在新选项卡中打开该链接,则会获得404.
这是我的pom和web.xml文件:
的pom.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confPath</param-name>
<param-value>/WEB-INF/urlrewrite.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
web.xml中:
<urlrewrite>
<rule match-type="wildcard">
<from>*/page</from>
<to>index.html</to>
</rule>
// what should this rule look like in order to recognize a url like:
// localhost:8080/mypage/category/subcategory/item
<rule match-type="wildcard">
<from>?</from>
<to>index.html</to>
</rule>
</urlrewrite>
Run Code Online (Sandbox Code Playgroud)
我在这里阅读了UrlRewriteFilter文档并尝试使用通配符匹配和正则表达式语法的不同变体,但我总是得到404.
我还要补充一点,我正在使用angular-ui-router版本0.2.13,我的网页/状态的url看起来像/ mypage /:category /:subcategory /:item.
所以我的问题是如何匹配这种模式,以便重定向到index.html对html5mode正常工作,或者我应该以不同方式配置路由以更好地与UrlRewriteFilter一起使用?