Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

RESOLVED: Redirect after short delay on Error 404 page

Go to End

4 Posts   4350 Views


Community Member, 11 Posts

4 May 2009 at 4:40pm

Edited: 08/05/2009 1:56pm


Another question regarding 404 pages - I want my 404 page to automatically redirect the user to the front page of the site after 10 seconds. Is it possible to do this via the CMS, or do I need to hack some JavaScript in to the file after publishing?


P.S. For another 404 question, see:


Community Member, 70 Posts

4 May 2009 at 9:51pm

Another Ronan on the forum? Damn, I was sure I would be unique for a while longer!

Ok, so what you want to do is create an ErrorPage type in your theme:

1) in the \themes\YOURTHEME\templates folder, you should see at least a - copy this and rename the copy as
2) in the \themes\YOURTHEME\templates\Layout folder - there will be another - again make a copy as an

The in the ./templates directory is the main holder file. This will contain the <head> tags to which you can add in a bit of Jscript to redirect to the home page after 10 seconds or whatever you need.

The downside to this is that you will now have two main files in the ./templates directory to maintain. Most page types can work off the standard one, only requiring a files in the Layout folder, but aside from that, should work fine.

Don't forget to append ?flush=1 to the querystring to see the changes take effect.



Community Member, 11 Posts

5 May 2009 at 12:24pm

Hey Ronan,

Cheers for the help, I take it Silverstripe just looks for the file, and if it doesn't find it there, it just uses the file? I've had a quick look at the file and I know this is a bit cheeky, but as I only want the redirect on a 404 error (for a 500 I want to leave the user sitting there), can I driectly code a bit of PHP (or Silverstripe code) to check the ErrorCode and thus only include the redirect header for 404s? If so, I'll probably just go with a HTML redirect rather than a Javascript one.

Ronan 2.0

P.S. Good name, btw, I love the fact that it's exotic in NZ, I know far too many Ronans at home - kinda like the Irish equivalent of Dave in NZ...


Community Member, 11 Posts

8 May 2009 at 1:55pm

See my other post regarding the issue of emailing the sysadmin when a site error occurs. The following code can be added in after the mail command so that the user is redirected to the front page of the site after 5 seconds.

// Once Email is sent, set up the redirect
  $redirectDest = "/";  // i.e. homepage of site
  $redirectDelay = "5000";  // 5000ms (5 sec) delay
  $redirect = '
setTimeout(\'window.location = "'.$redirectDest.'"\','.$redirectDelay.')
  if ($_GET["err_code"]=="404") echo $redirect;  // Only do the redirect on 404 errors.

Hope this helps others.

Ronan 2.0