[英]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.