JSF UrlRewriteFilter catchall / 404 replacement

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

Purpose: - any request that does not match an existing file; or - Any query that does not comply with the previous rules ... should start a search through search.jsf?q= . It is designed to handle any possible dead link from the old site and to replace a 404 page with something more functional (to help the user find what he is actually looking for).

Partial code (other rules are similar to the second, only the default rule will fail):

 <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> 

This causes a stack overflow because it matches search.jsf - [^\s]+ , although there is a physical file matching search.jsf .

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

I read the UrlRewriteFilter manual and could not find anything except last="true" , which theoretically should stop the process from checking for other matches if it is already found.

Many thanks!

EDIT: With no answers and my inability to solve this problem, I checked an alternate way. See this question here.

+3
source share
1 answer

I don't know anything about tuckey, but I can think of two simple solutions:

1 Create a search rule that rewrites the URL, for example /search?q=foo to /search.jspf?q=foo

I guess something like:

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

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

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

2 Rewrite the standard regex matching rule to exclude search.jspf using a negative view:

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

Source: https://habr.com/ru/post/1497291/


All Articles