Tomcat URL 重写过滤器不转发 [英] Tomcat URL Rewrite Filter isn't forwarding

查看:49
本文介绍了Tomcat URL 重写过滤器不转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转发所有与模式匹配的网址:

I'd like to forward all URLs matching the pattern:

http://localhost:8080/docs/view.php?fDocumentId=([0-9]+)

到:

http://localhost:8080/alfresco/service/org/docs/redirect/document/properties/$1

这是在 tomcat 上,并且有两个主要的 webapps 正在加载:docs" &露天".
为简单起见,我们旧的遗留应用程序(基于 LAMP)的所有 URL 都以/docs 作为路径的第一部分,与新应用程序相同.我转发到/alfresco 的原因是因为我开发了一个 web 脚本,用于将旧 URL 解析为新 URL 并再次重定向回/docs,但这与此问题无关.

This is on tomcat, and there are two primary webapps being loaded: "docs" & "alfresco".
For simplicity sake, our old legacy application (LAMP based) had all URLS with /docs as the first part of the path, same as the new application. The reason I am forwarding to /alfresco is because of a webscript that I've developed to parse the old URL into a new URL and perform yet another redirect back to /docs, but this is irrelevant to this question.

新系统已经加载了 URLRewriteFilter,但缺少以下提到的特定代码在需要放入 webapps/docs/WEB-INF/web.xml 的谷歌代码站点(我添加的)上:

The new system already has the URLRewriteFilter loaded, but was lacking the following specific code mentioned on the google code site (which I added) that needs to be put in webapps/docs/WEB-INF/web.xml:

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

然后我在与 web.xml 相同的目录中的 urlrewrite.xml 中添加了以下规则:

I then added the following rule to urlrewrite.xml in the same directory as web.xml:

<rule>
   <from>^/docs/view.php?fDocumentId=([0-9]+)</from>
   <to>/alfresco/service/org/docs/redirect/document/properties/$1</to>
</rule>

我在尝试访问 http://localhost:8080/docs/view.php?fDocumentId=12345

推荐答案

您的 都不正确.

Both your <from> and your <to> are incorrect.

首先,您的 需要相对于已经是 /docs 的当前上下文(即 webapp),因此您需要:

First, your <from> needs to be relative to the current context (i.e. webapp) which is already /docs, so you want this:

<from>^/view.php?fDocumentId=([0-9]+)</from>

其次,您的 也必须与当前上下文相关,除非您指定 context 属性上下文被定义为跨上下文.所以,你需要这个:

Second, your <to> has to be relative to the current context, too, unless you specify the context attribute and your context is defined to be cross-context. So, you'll need this:

<to context="/alfresco">/service/gov/inteldocs/redirect/document/properties/$1</to>

您还需要在 META-INF/context.xml 文件中使用它:

and you'll also need this in your META-INF/context.xml file:

<Context ... crossContext="true" ... />

请注意,这两个警告都在 http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html#fromhttp://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html#to(包括后者的示例).

Note that both of these caveats are clearly stated in the url-rewrite documentation at http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html#from and http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html#to (including examples for the latter).

这篇关于Tomcat URL 重写过滤器不转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆