[英]Jetty config to redirect all 404s to home page
Google 已将一些旧 URL 缓存到站点上不再存在的页面。 我想将任何 404 页面重定向到主页。
我在jetty/webapps 中安装了一个带有ROOT.war 文件的jetty 安装。 ROOT.war 文件包含一个 WEB-INF/web.xml 文件,其中包含以下内容:
<error-page>
<error-code>404</error-code>
<location>/</location>
</error-page>
但是,这只是重定向顶级文件,在子目录中没有任何内容。 因此,以下 URL 被重定向到主页:
http://mysite.com/pageDoesntExist.html
但是这个没有,只是给出了一个 404 错误:
http://mysite.com/directoryDoesntExist/pageDoesntExist.html
有没有办法将所有 404 配置为转到主页? 我可以在 jetty/contexts 目录中以某种方式执行此操作吗?
你想使用 org.mortbay.jetty.handler.MovedContextHandler: http : //jetty.mortbay.org/xref/org/mortbay/jetty/handler/MovedContextHandler.html
Bots 将使用 Header 301 Redirect 来更新缓存 google
一个想法是:
<error-page>
<error-code>404</error-code>
<location>/error404.html</location>
</error-page>
(如Redirecting a 404 error page to a custom page of my Spring MVC webapp in Tomcat 中所述)然后在error404.html
进行重定向:
<html>
<head><title>Redirecting...</title></head>
<body>
<script>
document.location.href="/";
</script>
</body>
</html>
(如如何重定向到主页中所述)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.