首页 > 解决方案 > Apache Tomcat 9 重写阀不起作用

问题描述

我一直在尝试设置我的 tomcat 9 重写阀(在全局级别)但没有成功,按照我在互联网上找到的每个教程进行操作,但无论我如何配置我的 rewirte.config,阀都无法正常工作。

所以我写了我能想到的最简单的rewrite.config,它只包含一行:

RewriteRule ^test$ manager/test.jpg

所以这条规则只是意味着将http://localhost:8080/test重写为http://localhost:8080/manager/test.jpg

这个文件放在 $CATALINA_HOME/conf/Catalina/localhost 我已经在 localhost.2018-08-30.log 日志文件中验证了阀门已正确加载:

30-Aug-2018 14:32:43.530 FINE [main] org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with pattern ^test$ and substitution manager/test.jpg

但是,当我重新启动 tomcat 并对其进行测试时,URL http://localhost:8080/test给了我一个 404 错误,而 URL http://localhost:8080/manager/test.jpg正确加载了实际图像。

访问日志显示:

127.0.0.1 - - [30/Aug/2018:14:39:50 +0800] "GET /test HTTP/1.1" 404 1078
127.0.0.1 - - [30/Aug/2018:14:42:34 +0800] "GET /manager/test.jpg HTTP/1.1" 304 -

那么我错过了什么?

标签: tomcaturl-rewriting

解决方案


推荐阅读