-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redirect from www to bare domain
- Loading branch information
1 parent
663a58e
commit 3ff4843
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// AWS runtime: 'cloudfront-js-2.0' | ||
// This function is intended to run as part of the 'Viewer Request' event in CloudFront, where it | ||
// checks and redirects requests from 'www.whoisthecutest.com' to 'whoisthecutest.com'. | ||
|
||
function handler(event) { | ||
var request = event.request; | ||
var headers = request.headers; | ||
|
||
var bareDomain = 'whoisthecutest.com'; | ||
|
||
if (headers.host && headers.host.value === 'www.' + bareDomain) { | ||
return { | ||
statusCode: 308, | ||
statusDescription: 'Permanent Redirect', | ||
headers: { | ||
// Redirects to the bare domain without preserving the path (request.uri). | ||
// Since the site is a single-page application, only the base domain is needed for the redirect. | ||
location: { value: 'https://' + bareDomain }, | ||
}, | ||
}; | ||
} | ||
|
||
// If the host doesn't match 'www.whoisthecutest.com', proceed without redirection. | ||
return request; | ||
} |