404 and Redirect Question

Started by manvbf, 10-29-2011, 03:46:16

Previous topic - Next topic

manvbfTopic starter

So I have the custom error pages set up and working fine, but I was just thinking of adding a META refresh that redirects to the site home page after 30 seconds or so. Has anyone tried this? Will the SEs be OK with this? Or will they think I'm "up to something"...?

Thanks!
  •  


freeplusac

hi

Don't render 404 yourself, there's no reason to; Rails has this functionality built in already. If you want to show a 404 page, create a render_404 method (or "not_found" as I called it) in ApplicationController like this:

def not_found
  raise ActionController::RoutingError.new('Not Found')
end

Rails also handles AbstractController::ActionNotFound, and ActiveRecord::RecordNotFound the same way.

This does two things better:

1) It uses Rails' built in rescue_from handler to render the 404 page, and 2) it interrupts the execution of your code, letting you do nice things like:

  user = User.find_by_email(params[:email]) || not_found
  user.do_something!

without having to write ugly conditional statements.

As a bonus, it's also super easy to handle in tests. For example, in an rspec integration test:

lambda {
  visit '/something/you/want/to/404'
}.should raise_error(ActionController::RoutingError)



takeshiro

i agree that there is no reason for you to make a 404 page. there's, like, a default for that.

eetplus

I think it's good idea to redirect 404 page to home page after some seconds.
Elan - Web & Mobile Application Development Company
  •  

smith

Hi,
404 redirect of the website make it crawler friendly, otherwise there will be chances that the trust-ability of the site may decreased.
This will also increase the bounce rate of the site, try to avoid it.


Yuga

404 redirects are server response code informing a user that the web page he or she is looking for cannot be found; either due to user error when typing the url, or the web page he or she is looking for is not an actual web page.