繁体   English   中英

Tomcat 重写 url 给出 404 而直接浏览给出 200

[英]Tomcat rewrite url gives 404 while direct browsing gives 200

我想我在发布之前做了一些搜索。 找不到类似的问题。 我正在使用 apache-tomcat-9.0.37。 我正在尝试将请求从 /contextOld/ 转发到 /context-new/。

它成功地重写为新的 url。但是当 tomcat 重写为新的 url 时,它给出了 404。通过浏览器直接访问时给出了 200。

本地主机日志

30-Sep-2021 14:01:27.250 FINE [http-nio-8080-exec-8] org.apache.catalina.core.ApplicationDispatcher.doForward  The Response is vehiculed using a wrapper: org.springframework.security.web.firewall.FirewalledResponse
30-Sep-2021 14:02:58.978 FINE [http-nio-8080-exec-3] org.apache.catalina.valves.rewrite.RewriteValve.invoke Rewrote /contextOld/mainPage.htm as /context-new/mainPage.htm with rule pattern ^/contextOld/(.*)$
30-Sep-2021 14:04:31.042 FINE [http-nio-8080-exec-1] org.apache.catalina.core.ApplicationDispatcher.doForward  Disabling the response for further output
30-Sep-2021 14:04:31.042 FINE [http-nio-8080-exec-1] org.apache.catalina.core.ApplicationDispatcher.doForward  The Response is vehiculed using a wrapper: org.springframework.security.web.firewall.FirewalledResponse
30-Sep-2021 14:05:52.290 FINE [http-nio-8080-exec-1] org.apache.catalina.valves.rewrite.RewriteValve.invoke Rewrote /contextOld/mainPage.htm as /context-new/mainPage.htm with rule pattern ^/contextOld/(.*)$
30-Sep-2021 14:11:01.225 FINE [http-nio-8080-exec-8] org.apache.catalina.valves.rewrite.RewriteValve.invoke Rewrote /contextOld/mainPage.htm as /context-new/mainPage.htm with rule pattern ^/contextOld/(.*)$
30-Sep-2021 14:11:47.901 FINE [http-nio-8080-exec-6] org.apache.catalina.valves.rewrite.RewriteValve.invoke Rewrote /contextOld/mainPage.htm as /context-new/mainPage.htm with rule pattern ^/contextOld/(.*)$
30-Sep-2021 14:12:23.485 FINE [http-nio-8080-exec-8] org.apache.catalina.valves.rewrite.RewriteValve.invoke Rewrote /contextOld/mainPage.htm as /context-new/mainPage.htm with rule pattern ^/contextOld/(.*)$
30-Sep-2021 14:12:24.752 FINE [http-nio-8080-exec-6] org.apache.catalina.valves.rewrite.RewriteValve.invoke Rewrote /contextOld/mainPage.htm as /context-new/mainPage.htm with rule pattern ^/contextOld/(.*)$
30-Sep-2021 14:41:04.800 FINE [http-nio-8080-exec-2] org.apache.catalina.valves.rewrite.RewriteValve.invoke Rewrote /contextOld/mainPage.htm as /context-new/mainPage.htm with rule pattern ^/contextOld/(.*)$

下面访问日志中的第二个请求是通过浏览器直接访问 url 时

localhost_access.log

0:0:0:0:0:0:0:1 - - [30/Sep/2021:14:41:04 +0000] "GET /context-new/mainPage.htm HTTP/1.1" 404 653 [2]
0:0:0:0:0:0:0:1 - - [30/Sep/2021:14:41:57 +0000] "GET /context-new/mainPage.htm HTTP/1.1" 200 9401 [69]

重写.config

RewriteCond %{REQUEST_URI} ^/contextOld/.*$
RewriteRule ^/contextOld/(.*)$ /context-new/$1 [L]

服务器.xml

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">     
        <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b [%D]" />
               
        <Valve className="org.apache.catalina.valves.ErrorReportValve" errorCode.400="/webapps/Error/error.html" showServerInfo="false"/>

      </Host>

如果我在这里遗漏了任何其他相关的 tomcat 配置,我可以提供。

如果/contextOld不对应于任何应用程序(您既没有ROOT应用程序也没有/contextOld应用程序),您可能偶然发现了错误 64593

这已在Tomcat 9.0.38中得到纠正,因此您只需升级到最新版本即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM