为什么我的 UrlRewriteFilter 在 Tomcat 上不起作用?

发布于 2024-12-11 16:46:45 字数 2072 浏览 0 评论 0原文

摘要

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞取 2024-12-18 16:46:45

添加或删除尾部正斜杠 (/) 会有什么不同吗?可以尝试将其设置为规则标记集的 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.

护你周全 2024-12-18 16:46:45

@Mike是对的,

<from>/test/status/</from>

改为

<from>/test/status</from>

@Mike is right, change

<from>/test/status/</from>

to

<from>/test/status</from>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文