One of our clients has Microsites transferred to independent domains. The Microsite URL is like www.rewards.com/loyalty1 and it’s moved to www.loyalty1.com. The hosting of both the sites are in AWS S3 with Cloudfront.
This is permanent change, and we all know that it should be 301 permanent redirect. As you see in this post, we have to update the Redirect rules in S3. The client has configured the rules, but they have old campaigns with UTM values referring to the earlier domain. As per S3 redirect rules, the sites are redirecting to new domain, but it does not preserve the query strings.
I have noticed two issues,
- When I checked through browser developer tools, two round-trips happening. First, https://www.rewards.com/loyalty1?utm_source=fall2020 to http://www.loyalty1.com and then redirects to https://www.loyalty1.com
- UTM values in the query strings are missing.
Referring the AWS documentation, noticed an element we can add to the rules. Protocol
, this can be http
, https
or none
. This will force the redirects to the protocol configured. This element is missing in the rules, so one other round-trip.
The issue of losing the campaign query strings during the redirect is because of the element ReplaceKeyWith
. There is an excellent discussion at stackoverflow. So use ReplaceKeyPrefixWith
.
Finally, following is the rule we configured,
{
{
"Condition": {
"KeyPrefixEquals": "loyalty1"
},
"Redirect": {
"HostName": "loyalty1.com",
"HttpRedirectCode": "301",
"Protocol": "https",
"ReplaceKeyPrefixWith": ""
}
}
}
This is redirecting to the new domain, but still there is one issue. The condition check is case sensitive. I don’t see any regex references in the documentation for redirect rules. Anyone has an alternate solution for this?
Top comments (1)
This should help - stackoverflow.com/a/70428718