我设置我的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在匹配规则后不要连接网址? 我是否以错误的方式在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 log:(摘录)
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>
答案 0 :(得分:0)
它源于我计算base
网址的方式的错误。在head
的第一行添加后,资源就可以正常加载。
<base href='http://localhost:8080/<MY_APP_NAME>/'/>