【问题标题】:Why isn't my UrlRewriteFilter working on Tomcat?为什么我的 UrlRewriteFilter 不能在 Tomcat 上运行?
【发布时间】:2011-12-12 22:42:38
【问题描述】:

总结

我无法在 Tomcat 上启动和运行 UrlRewriteFilter。

问题

我只能从默认的 urlrewrite.xml 文件中获取两个规则之一来工作。我遵循installation directions 没有太大问题,我没有更改任何默认值或弄乱配置文件。

示例

出站规则有效: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>

【问题讨论】:

标签: apache web-applications tomcat


【解决方案1】:

添加或删除尾部正斜杠 (/) 会有所不同吗?可以尝试在规则标记集的 from 和 to 标记中设置它。

【讨论】:

    【解决方案2】:

    @Mike 是对的,改变

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

    <from>/test/status</from>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 2014-09-07
      相关资源
      最近更新 更多