From f194d65ee5e1cf5a9e78c95ff6159a2b5ac7d614 Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Thu, 24 Sep 2026 21:31:30 +0000 Subject: [PATCH] fix(careers): return 301s for retired job URLs (DEV-297) (#68) * fix(careers): return 301s for retired job URLs Send the old careers paths to the Paychex portal from the viewer-request function so clients get a permanent redirect instead of the HTML stub. * fix(careers): match retired job redirects case-insensitively CloudFront does not normalize URI case, so a mixed-case old job link skipped the 301 and missed the lowercase S3 stub. --- terraform/cloudfront.tf | 7 ++++--- terraform/functions/directory-index.js | 28 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/terraform/cloudfront.tf b/terraform/cloudfront.tf index e30e986..e9938a0 100644 --- a/terraform/cloudfront.tf +++ b/terraform/cloudfront.tf @@ -6,12 +6,13 @@ resource "aws_cloudfront_origin_access_control" "site" { signing_protocol = "sigv4" } -# Viewer-request rewrite so pretty URLs (/sustainability/) fetch S3 key -# sustainability/index.html. default_root_object only covers "/". PLAT-105. +# Viewer-request: 301 retired /careers job URLs to the Paychex portal, then +# rewrite pretty URLs (/sustainability/) to index.html. default_root_object +# only covers "/". PLAT-105. resource "aws_cloudfront_function" "directory_index" { name = "seahaven-site-prod-directory-index" runtime = "cloudfront-js-2.0" - comment = "Rewrite directory and extensionless URIs to index.html" + comment = "301 retired job URLs and rewrite directory URIs to index.html" publish = true code = file("${path.module}/functions/directory-index.js") } diff --git a/terraform/functions/directory-index.js b/terraform/functions/directory-index.js index 5b6e0e5..c2e3d4f 100644 --- a/terraform/functions/directory-index.js +++ b/terraform/functions/directory-index.js @@ -1,6 +1,34 @@ +var PORTAL_URL = "https://jobs.appone.com/seahaven"; + +// Retired local job pages. Redirect before the directory-index rewrite so +// these paths never fall through to the HTML stubs in S3. +var RETIRED_JOB_URIS = { + "/careers/dispatcher": 1, + "/careers/dispatcher/": 1, + "/careers/dispatcher/index.html": 1, + "/careers/scheduling-coordinator": 1, + "/careers/scheduling-coordinator/": 1, + "/careers/scheduling-coordinator/index.html": 1, + "/careers/traveling-maintenance-assistant": 1, + "/careers/traveling-maintenance-assistant/": 1, + "/careers/traveling-maintenance-assistant/index.html": 1 +}; + function handler(event) { var request = event.request; var uri = request.uri; + + // CloudFront does not normalize URI case. The S3 keys are lowercase. + if (RETIRED_JOB_URIS[uri.toLowerCase()]) { + return { + statusCode: 301, + statusDescription: "Moved Permanently", + headers: { + location: { value: PORTAL_URL } + } + }; + } + var last = uri.substring(uri.lastIndexOf("/") + 1); // S3 OAC has no directory index. default_root_object only covers "/".