Google has cached some old URLs to pages that no longer exist on a site. I'd like to redirect any 404 pages to the home page.
I have a jetty installation with a ROOT.war file installed in jetty/webapps. The ROOT.war file contains a WEB-INF/web.xml file that has the following in it:
<error-page>
<error-code>404</error-code>
<location>/</location>
</error-page>
However, this is only redirecting top level files, nothing in subdirectories. So the following URL get redirected to the home page:
http://mysite.com/pageDoesntExist.html
But this one doesn't and just gives a 404 error:
http://mysite.com/directoryDoesntExist/pageDoesntExist.html
Is there a way to configure all 404's to go to the home page? Can I do this in the jetty/contexts directory somehow?
You want to use the org.mortbay.jetty.handler.MovedContextHandler: http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/MovedContextHandler.html
Bots will use the Header 301 Redirect to update the cache google
An idea is:
<error-page>
<error-code>404</error-code>
<location>/error404.html</location>
</error-page>
(as described in Redirecting a 404 error page to a custom page of my Spring MVC webapp in Tomcat ) and then inside error404.html
do a redirect:
<html>
<head><title>Redirecting...</title></head>
<body>
<script>
document.location.href="/";
</script>
</body>
</html>
(as described in how to redirect to home page )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.