Skip to content

Commit 8d95cd0

Browse files
committed
redirects: always strip trailing slash
1 parent c80922a commit 8d95cd0

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

astro.config.mjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import sitemap from "@astrojs/sitemap";
55
import react from "@astrojs/react";
66

77
export default defineConfig({
8-
site: process.env.ASTRO_SITE || undefined,
8+
site: process.env.ASTRO_SITE || "https://www.materialscloud.org",
99
base: process.env.ASTRO_BASE || "/",
10-
1110
vite: {
1211
resolve: {
1312
alias: {
@@ -18,7 +17,14 @@ export default defineConfig({
1817
},
1918
plugins: [tailwindcss()],
2019
},
21-
22-
site: "https://www.materialscloud.org",
2320
integrations: [react(), sitemap()],
21+
22+
// ----
23+
// Canonicalize URLs without trailing slash
24+
trailingSlash: "never",
25+
build: {
26+
// needed for Cloudflare - otherwise "directory" redirects to trailing slash
27+
format: "file",
28+
},
29+
// ----
2430
});

public/_redirects

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
# Redirect configuration file for Cloudflare pages
33
# --------------------------------------------------------
44

5+
# Strip trailing slashes globally
6+
/*/ /:splat 301
7+
58
# Navitation to external pages
69
/aiidalab https://www.aiidalab.net/ 301
710
/work/aiidalab https://www.aiidalab.net/ 301
811
/archive https://archive.materialscloud.org/ 301
912
/moderation https://archive.materialscloud.org/information#moderation_policies 301
1013
/work/quantum-mobile https://quantum-mobile.readthedocs.io/en/latest/ 301
1114

12-
# Old file paths match new S3 307 means keep the headers and path
15+
# Old file paths match new S3
1316
/learn/data/learn/files/* https://rgw.cscs.ch/matcloud:mc-public/learn-data/files/:splat 302
1417

1518
# dropping old url syntax
@@ -41,23 +44,14 @@
4144
/discover/3dcd /discover/mc3d 301
4245
/discover/2dstructures /discover/mc2d 301
4346

44-
# trailing slash names
45-
/discover/mc3d/ /discover/mc3d 301
46-
/discover/mc2d/ /discover/mc2d 301
47-
/discover/sssp/ /discover/sssp 301
48-
/discover/acwf-verification/ /discover/acwf-verification 301
49-
50-
5147
# Contributed sections
52-
# /discover/2dtopo https://legacy.materialscloud.org/discover/2dtopo 302 // migrated into mc2d with standalone page
48+
/discover/2dtopo https://legacy.materialscloud.org/discover/2dtopo 302
5349
/discover/autowannier https://legacy.materialscloud.org/discover/autowannier 302
5450

5551
/discover/kpcovr https://kpcovr.materialscloud.io/ 302
5652
/discover/kpcovr/:dataset https://kpcovr.materialscloud.io/?dataset=:dataset 302
5753

5854

59-
60-
6155
# -------------- Tools --------------
6256

6357
# Core tools
@@ -86,9 +80,6 @@
8680
/tbeta /work/tools/tbeta 301
8781
/layer-raman-ir /work/tools/layer-raman-ir 301
8882

89-
/work/tools/shiftml* https://shiftml.materialscloud.io/ 301
90-
91-
9283
# -------------- OPTIMADE APIs --------------
9384
/optimade https://optimade.materialscloud.org 301
9485
/optimade/main https://optimade.materialscloud.org/main/index/links 301

src/layouts/Layout.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const {
99
padding = "py-5 px-7 mb-4",
1010
} = Astro.props;
1111
12-
const baseHref = (import.meta.env.BASE_URL || "/").replace(/\/?$/, "/"); // also add trailing slash if not present
12+
// const baseHref = (import.meta.env.BASE_URL || "/").replace(/\/?$/, "/"); // also add trailing slash if not present
13+
14+
const baseHref = (import.meta.env.BASE_URL || "/")
1315
1416
const activeSection =
1517
breadcrumbs.length > 0 ? breadcrumbs[0].name.toLowerCase() : "";

0 commit comments

Comments
 (0)