Re: 404 rewrite handler for images

Splash Forums Rewrite Users 404 rewrite handler for images Re: 404 rewrite handler for images

#22568

Hey Aaron,

I think something like this should be easy to do with Rewrite. The following example shows how something like this *could* work in a plain Servlet environment (without JSF resource loading):

.defineRule()
.when(new HttpCondition() {
@Override
public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context)
{
if(Direction.isInbound().evaluate(event, context)) {

String path = event.getRequestPath();
InputStream stream = event.getRequest().getServletContext().getResourceAsStream(path);
if(stream == null) {
return true;
}

}
return false;
}
}
).perform(Forward.to("/images/fallback.png"));

But if you are using the JSF resource loading, checking whether a resource exists would work a bit different.

Christian