为什么我的 UrlRewriteFilter 在 Tomcat 上不起作用?
摘要
我在 Tomcat 上启动和运行 UrlRewriteFilter 时遇到问题。
问题
我只能从默认的 urlrewrite.xml 文件中获取两个规则之一来工作。我按照安装说明进行操作,没有做太多操作问题,我没有更改任何默认值或弄乱配置文件。
示例
出站规则有效: http://localhost:8080/mysite/rewrite- status 成功将我带到 urlrewrite.xml 文件的描述页面。
但常规规则不起作用: http://localhost:8080/mysite/test/status 不会将我重定向到 http://localhost:8080/mysite/rewrite-status。我得到 404 结果。
我对这些规则的期望是否错误?可能出什么问题了?
详细信息
这是安装时附带的 urlrewrite.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://www.tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>
<rule>
<note>
The rule means that requests to /test/status/ will be redirected to /rewrite-status
the url will be rewritten.
</note>
<from>/test/status/</from>
<to type="redirect">%{context-path}/rewrite-status</to>
</rule>
<outbound-rule>
<note>
The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
the url /rewrite-status will be rewritten to /test/status/.
The above rule and this outbound-rule means that end users should never see the
url /rewrite-status only /test/status/ both in their location bar and in hyperlinks
in your pages.
</note>
<from>/rewrite-status</from>
<to>/test/status/</to>
</outbound-rule>
</urlrewrite>
Summary
I am having trouble getting UrlRewriteFilter up and running on Tomcat.
Problem
I can only get one of the two rules from the default urlrewrite.xml file to work. I followed the installation directions without much of a problem and I haven't changed any defaults or messed with the configuration file.
Example
The outbound rule works: http://localhost:8080/mysite/rewrite-status successfully takes me to a description page of my urlrewrite.xml file.
But the regular rule doesn't work: http://localhost:8080/mysite/test/status does not redirect me to http://localhost:8080/mysite/rewrite-status. I get a 404 result.
Am I expecting the wrong thing from these rules? What could be wrong?
Details
Here is the urlrewrite.xml file that comes with the installation:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://www.tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>
<rule>
<note>
The rule means that requests to /test/status/ will be redirected to /rewrite-status
the url will be rewritten.
</note>
<from>/test/status/</from>
<to type="redirect">%{context-path}/rewrite-status</to>
</rule>
<outbound-rule>
<note>
The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
the url /rewrite-status will be rewritten to /test/status/.
The above rule and this outbound-rule means that end users should never see the
url /rewrite-status only /test/status/ both in their location bar and in hyperlinks
in your pages.
</note>
<from>/rewrite-status</from>
<to>/test/status/</to>
</outbound-rule>
</urlrewrite>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加或删除尾部正斜杠 (/) 会有什么不同吗?可以尝试将其设置为规则标记集的 from 和 to 标记的两者或其中之一。
Does adding or removing trailing forward slash (/) make a difference? Could experiment with setting it in both or either for the from and to tags of rule tag set.
@Mike是对的,
改为
@Mike is right, change
to