微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Tomcat 8 URL重写

如何解决Tomcat 8 URL重写

我已经找到解决方案,问题出在错误/故障的rewrite.config文件中。正确的应该是:

RewriteCond %{REQUEST_URI} ^/(css|img|js|partials|rest|favicon).*$
RewriteRule ^.*$ - [L]

RewriteRule ^.*$ /index.html [L,QSA]

第一行是枚举的URI,不应重写。其他所有内容将被重写为index.html。

解决方法

我有一个AngularJS
webapp和Jersey后端。我需要设置URL重写,因此除给定的例外之外的所有内容都将重写为Angular的index.html。

例如。:

http://my.domain.com/about will be rewritten
http://my.domain.com/photos/photo1.jpg will NOT be rewritten (file photo 1 exists)
http://my.domain.com/rest/myservice will be NOT be rewritten (it is a call to REST service)

我已经如下设置了Tomcat 8 URL重写阀:

conf / server.xml中

<Host name="my.domain.com" appBase="webapps/MyDomainServer" unpackWARs="true"
           autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">
  <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
  <!-- access logging,aliases,...-->
</Host>

conf / Catalina / my.domain.com / rewrite.config中

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} ^/rest.*
RewriteRule ^ - [L]

RewriteRule ^ index.html [L]

Tomcat忽略了我的重写设置,没有任何重写,日志中没有错误/异常。我究竟做错了什么?提前致谢。

我试图将RewriteValve移至META-INF中的config.xml并将config重写为WEB-INF,但是它的行为方式相同。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。