Hi, there!
I was trying to use onMissingTemplate
to handle “page 404” errors on my website. But when I tried to use location()
to redirect the user to my custom 404 page, it doesn’t work.
This is my original code in the Application.cfc:
function onMissingTemplate(string targetPage)
{
location(url="/error-404/", addtoken=false);
}
I also tried to use cfheader()
to make it work, but it also doesn’t:
function onMissingTemplate(string targetPage)
{
cfheader(name="Location", value="/error-404/");
abort;
}
It seems like it’s simply ignored by lucee and the actual error is displayed on the screen.
It only WORKED when I tried onError
handler instead:
function onError(struct exception, string eventName)
{
if (exception.type EQ "missinginclude") {
location(url="/error-404/", addtoken=false);
}
}
Am I doing something wrong using onMissingTemplate
or is it just the way it works? If it is, why?
Thanks for your help!
OS: Windows Server 2016
Java Version: 11.0.7 (AdoptOpenJDK) 64bit
Tomcat Version: Apache Tomcat/9.0.35
Lucee Version: Lucee 5.3.6.61