Skip to content

Commit 08c1946

Browse files
authored
Merge pull request #1 from RustCFML/release-1.0.0
Answer www.rustcfml.org and redirect it to the apex
2 parents 0e729da + 1c9138e commit 08c1946

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/lib.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ pub async fn fetch(req: Request, env: Env, ctx: Context) -> Result<Response> {
110110
let config = build_config();
111111

112112
let mut url = req.url()?;
113+
114+
// One canonical hostname. sitemap.xml and robots.txt both name the apex,
115+
// so www is answered only to send visitors there, path and query intact.
116+
if let Some(apex) = url.host_str().and_then(|h| h.strip_prefix("www.")) {
117+
let apex = apex.to_string();
118+
url.set_host(Some(&apex))?;
119+
return Response::redirect_with_status(url, 301);
120+
}
121+
113122
let target = resolve(url.path());
114123
if target == url.path() {
115124
return cfml_worker::handle_fetch(req, env, ctx, &config).await;

‎wrangler.toml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ workers_dev = true
1717
pattern = "rustcfml.org"
1818
custom_domain = true
1919

20+
# www answers only to redirect to the apex, which is what sitemap.xml and
21+
# robots.txt name as canonical. A plain route rather than a custom domain:
22+
# the zone already has a proxied CNAME for www, and a route binds to an
23+
# existing proxied record, where a custom domain would want to create its
24+
# own and collide with it.
25+
[[routes]]
26+
pattern = "www.rustcfml.org/*"
27+
zone_name = "rustcfml.org"
28+
2029
# Static assets: anything present here is served directly, without invoking
2130
# (or billing for) the Worker. Anything else falls through to the Worker,
2231
# which is how the CFML pages get served. `public/` is generated by

0 commit comments

Comments
 (0)