Redirect trailing slashes
All checks were successful
CI / Check typos (push) Successful in 10s
CI / Check links (push) Successful in 1m6s
CI / Clippy (push) Successful in 1m6s
CI / Build and test (push) Successful in 1m4s
CI / Build container (push) Successful in 45s
CI / Deploy on waypoint (push) Successful in 46s

This commit is contained in:
2025-11-06 08:00:23 -08:00
parent 917c871763
commit 2603c835c6

View File

@@ -130,6 +130,28 @@ impl PageServer {
.and_then(|x| x.to_str().ok())
.unwrap_or("");
// Normalize url with redirect
if route.ends_with('/') {
let new_route = route.trim_end_matches('/');
trace!(
message = "Redirecting route",
route,
new_route,
addr = ?addr.addr,
user_agent = ua,
device_type = ?client_info.device_type
);
let mut headers = HeaderMap::with_capacity(2);
headers.append(
header::LOCATION,
HeaderValue::from_str(&format!("/{new_route}")).unwrap(),
);
headers.append("Accept-CH", HeaderValue::from_static("Sec-CH-UA-Mobile"));
return (StatusCode::PERMANENT_REDIRECT, headers).into_response();
}
trace!(
message = "Serving route",
route,