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
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:
@@ -130,6 +130,28 @@ impl PageServer {
|
|||||||
.and_then(|x| x.to_str().ok())
|
.and_then(|x| x.to_str().ok())
|
||||||
.unwrap_or("");
|
.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!(
|
trace!(
|
||||||
message = "Serving route",
|
message = "Serving route",
|
||||||
route,
|
route,
|
||||||
|
|||||||
Reference in New Issue
Block a user