【发布时间】:2014-08-14 03:34:16
【问题描述】:
我设置了我的 tomcat 服务器以使用 urlRewriterFilter 来启用 AngularJS 中的 html5 功能并从 url 中删除 #。似乎 urlRewriterFilter 可以正常处理以下格式的请求:
<SERVER>/<APP_NAME>/tracks - 页面加载正常。
问题: 是这样的请求:
<SERVER>/<APP_NAME>/tracks/<TRACK_NAME>/<TRACK_ID>。 - 加载 index.html 好的,但资源不是。
所以我得到 404,因为路径错误
<SERVER>/<APP_NAME>/tracks/<TRCK_NAME>/bower_components/underscore/underscore.js
代替:
<SERVER>/<APP_NAME>/bower_components/underscore/underscore.js
问题: 如何告诉 UrlRewriterFilter 在匹配规则后不要连接 url? 我是否以错误的方式在 index.html 中添加了库?
urlrewrite.xml
<urlrewrite default-match-type="wildcard">
<!-- All requests to root are forwarded to home page. -->
<rule>
<from>/signup</from>
<to>index.html</to>
</rule>
<rule>
<from>/tracks</from>
<to>index.html</to>
</rule>
<rule>
<from>/tracks/**</from>
<to>/index.html</to>
</rule>
</urlrewrite>
Chrom 开发控制台
GET http://localhost:8080/devstage-1.0/tracks/analysis/bower_components/moment/moment.js 404 (Not Found)
它尝试从http://localhost:8080/devstage-1.0/tracks/analysis而不是http://localhost:8080/devstage-1.0/加载时刻
UrlRewriteFilter 日志: (sn-p)
DEBUG|http-apr-8080-exec-2|o.s.s.web.FilterChainProxy | /tracks/analysis/bower_components/moment/moment.js at position 1 of 12 in additional filter chain; firing Filte
r: 'CORSFilter'
DEBUG|http-apr-8080-exec-10|o.s.s.web.FilterChainProxy | /tracks/analysis/bower_components/angular-route/angular-route.js at position 3 of 12 in additional filter chai
n; firing Filter: 'SecurityContextPersistenceFilter'
DEBUG|http-apr-8080-exec-8|o.s.s.web.FilterChainProxy | /tracks/analysis/bower_components/angularytics/dist/angularytics.js at position 1 of 12 in additional filter ch
ain; firing Filter: 'CORSFilter'
DEBUG|http-apr-8080-exec-2|o.s.s.web.FilterChainProxy | /tracks/analysis/bower_components/moment/moment.js at position 2 of 12 in additional filter chain; firing Filte
r: 'WebAsyncManagerIntegrationFilter'
我像这样在 index.html 中加载资源:
<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/underscore/underscore.js"></script>
【问题讨论】:
标签: html spring angularjs url-rewriting tuckey-urlrewrite-filter