@@ -10,18 +10,21 @@ pub(super) const DOC_RUST_LANG_ORG_REDIRECTS: &[&str] =
1010pub ( super ) fn build_routes ( ) -> Routes {
1111 let mut routes = Routes :: new ( ) ;
1212
13+ // Well known resources, robots.txt and favicon.ico support redirection, the sitemap.xml
14+ // must live at the site root:
15+ // https://developers.google.com/search/reference/robots_txt#handling-http-result-codes
16+ // https://support.google.com/webmasters/answer/183668?hl=en
1317 routes. static_resource ( "/robots.txt" , PermanentRedirect ( "/-/static/robots.txt" ) ) ;
1418 routes. static_resource ( "/favicon.ico" , PermanentRedirect ( "/-/static/favicon.ico" ) ) ;
19+ routes. static_resource ( "/sitemap.xml" , super :: sitemap:: sitemap_handler) ;
1520
16- // These should not need to be served from the root as we reference the inner path in links,
21+ // This should not need to be served from the root as we reference the inner path in links,
1722 // but clients might have cached the url and need to update it.
1823 routes. static_resource (
1924 "/opensearch.xml" ,
2025 PermanentRedirect ( "/-/static/opensearch.xml" ) ,
2126 ) ;
22- routes. static_resource ( "/sitemap.xml" , PermanentRedirect ( "/-/sitemap.xml" ) ) ;
2327
24- routes. static_resource ( "/-/sitemap.xml" , super :: sitemap:: sitemap_handler) ;
2528 routes. static_resource ( "/-/static/:file" , super :: statics:: static_handler) ;
2629
2730 routes. internal_page ( "/" , super :: releases:: home_page) ;
@@ -330,19 +333,19 @@ mod tests {
330333 #[ test]
331334 fn test_root_redirects ( ) {
332335 wrapper ( |env| {
333- // These are "well-known" resources that must be served from the root
336+ // These are "well-known" resources that will be requested from the root, but support
337+ // redirection
334338 assert_redirect ( "/favicon.ico" , "/-/static/favicon.ico" , env. frontend ( ) ) ?;
335339 assert_redirect ( "/robots.txt" , "/-/static/robots.txt" , env. frontend ( ) ) ?;
336340
337- // These have previously been served with a url pointing to the root, it may be
341+ // This has previously been served with a url pointing to the root, it may be
338342 // plausible to remove the redirects in the future, but for now we need to keep serving
339- // them .
343+ // it .
340344 assert_redirect (
341345 "/opensearch.xml" ,
342346 "/-/static/opensearch.xml" ,
343347 env. frontend ( ) ,
344348 ) ?;
345- assert_redirect ( "/sitemap.xml" , "/-/sitemap.xml" , env. frontend ( ) ) ?;
346349
347350 Ok ( ( ) )
348351 } ) ;
0 commit comments