JSF UrlRewriteFilter catchall/404替换 [英] JSF UrlRewriteFilter catchall/404 replacement

查看:81
本文介绍了JSF UrlRewriteFilter catchall/404替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Tuckey UrlRewrite设置URL规则.到目前为止,一切正常,但是我在默认页面上苦苦挣扎.

I'm setting up URL rules using Tuckey UrlRewrite. Everything to work so far, however I'm struggling with my default page.

目标: -任何与现有文件不匹配的请求;或者 -任何不符合先前规则的请求 ...应通过search.jsf?q=启动搜索.它的意思是处理来自旧版网站的任何可能的无效链接,并用功能更强大的功能替换404页面(以帮助用户找到他实际正在寻找的内容).

Objective: - Any request not matching existing file; or - Any request not matching previous rules ...should launch a search thru search.jsf?q=. It's meant to handle any possible dead link from the legacy website and to replace the 404 page with something more functional (to help the user find what he's actually is looking for).

部分代码(其他规则与第二个规则相似,只有默认"规则使其崩溃):

Partial code (the other rules are similar to the 2nd one, only the "default" rule makes it crash):

<rule>
  <name>Home</name>
  <from>^/$</from>
  <to type="forward" last="true">/home.jsf</to>
</rule>

<rule>
  <name>Contact Us</name>
  <from>^/contact_us/?$</from>
  <to type="forward" last="true">/contactUs.jsf</to>
</rule>

<rule>
  <name>Default + 404</name>
  <from>^/[^\s]+$</from>
  <to type="forward">^/search.jsf?q=$1</to>
</rule>

即使存在与search.jsf匹配的物理文件,它也会导致栈溢出,因为它将search.jsf匹配到[^\s]+.

It causes a stack overflow as it matches search.jsf to [^\s]+ even though there is a physical file matching search.jsf.

其他所有规则都具有last="true",因为它们都不应该重叠(很明显,该总体除外).

Every other rule has last="true" as none of them should overlap (except this catchall, obviously).

我阅读了 UrlRewriteFilter手册似乎没有找到除last="true"以外的任何内容,从理论上讲,这应该阻止该过程检查是否已找到其他匹配项.

I read the UrlRewriteFilter manual and couldn't seem to find anything besides last="true" which should, in theory, stop the process from checking for other matches if it already found one.

非常感谢!

编辑:由于没有答案,而且我无法解决此问题,因此我寻找了另一种方法.请在此处参考此问题.

With the lack of answers and my unability to solve this problem, I checked for an alternative way. Refer to this question here.

推荐答案

我对曲棍球一无所知,但是我可以想到两个简单的解决方案:

I know nothing of tuckey, but I can think of two simple solutions:

1 创建搜索规则,例如将/search?q=foo这样的网址重写为/search.jspf?q=foo

1 Create a rule for search like that rewrites a url like /search?q=foo to /search.jspf?q=foo

我猜是这样的:

<rule>
  <name>Search</name>
  <from>^/search\?(.*)$</from>
  <to type="forward" last="true">/search.jsf?\1</to>
</rule>

然后只需将默认规则更改为使用/search而不是实际文件/search.jspf:

Then simply change your default rule to use /search instead of the actual file /search.jspf:

<rule>
  <name>Default + 404</name>
  <from>^/[^\s]+$</from>
  <to type="forward">^/search?q=$1</to>
</rule>

2 重写默认规则的匹配正则表达式,以使用否定的前瞻明确排除search.jspf:

2 Rewrite your default rule's matching regex to specifically exclude search.jspf using a negative lookahead:

<rule>
  <name>Default + 404</name>
  <from>^/(?!search.jspf)[^\s]+$</from>
  <to type="forward">^/search.jspf?q=$1</to>
</rule>

这篇关于JSF UrlRewriteFilter catchall/404替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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