@@ -10,18 +10,21 @@ pub(super) const DOC_RUST_LANG_ORG_REDIRECTS: &[&str] =
10
10
pub ( super ) fn build_routes ( ) -> Routes {
11
11
let mut routes = Routes :: new ( ) ;
12
12
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
13
17
routes. static_resource ( "/robots.txt" , PermanentRedirect ( "/-/static/robots.txt" ) ) ;
14
18
routes. static_resource ( "/favicon.ico" , PermanentRedirect ( "/-/static/favicon.ico" ) ) ;
19
+ routes. static_resource ( "/sitemap.xml" , super :: sitemap:: sitemap_handler) ;
15
20
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,
17
22
// but clients might have cached the url and need to update it.
18
23
routes. static_resource (
19
24
"/opensearch.xml" ,
20
25
PermanentRedirect ( "/-/static/opensearch.xml" ) ,
21
26
) ;
22
- routes. static_resource ( "/sitemap.xml" , PermanentRedirect ( "/-/sitemap.xml" ) ) ;
23
27
24
- routes. static_resource ( "/-/sitemap.xml" , super :: sitemap:: sitemap_handler) ;
25
28
routes. static_resource ( "/-/static/:file" , super :: statics:: static_handler) ;
26
29
27
30
routes. internal_page ( "/" , super :: releases:: home_page) ;
@@ -330,19 +333,19 @@ mod tests {
330
333
#[ test]
331
334
fn test_root_redirects ( ) {
332
335
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
334
338
assert_redirect ( "/favicon.ico" , "/-/static/favicon.ico" , env. frontend ( ) ) ?;
335
339
assert_redirect ( "/robots.txt" , "/-/static/robots.txt" , env. frontend ( ) ) ?;
336
340
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
338
342
// plausible to remove the redirects in the future, but for now we need to keep serving
339
- // them .
343
+ // it .
340
344
assert_redirect (
341
345
"/opensearch.xml" ,
342
346
"/-/static/opensearch.xml" ,
343
347
env. frontend ( ) ,
344
348
) ?;
345
- assert_redirect ( "/sitemap.xml" , "/-/sitemap.xml" , env. frontend ( ) ) ?;
346
349
347
350
Ok ( ( ) )
348
351
} ) ;
0 commit comments