I'm setting up URL rules using Tuckey UrlRewrite. Everything to work so far, however I'm struggling with my default page.
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>
It causes a stack overflow as it matches search.jsf
to [^\s]+
even though there is a physical file matching search.jsf
.
Every other rule has last="true"
as none of them should overlap (except this catchall, obviously).
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.
Thank you very much!
EDIT: With the lack of answers and my unability to solve this problem, I checked for an alternative way. Refer to this question here.