6

I do not know why, but all my internal links are 301 redirects.

It is kind of absurd; each single internal link is being redirected to the same resource but as a relative URI.

Example: coinsocialmedia.com/coins/bitcoin => /coins/bitcoin

Test with Postman below:

enter image description here

I am afraid that my www subdomain redirection might have something to do with it (see below).

enter image description here

Can someone point me in the right direction?

10

If you look closely, you will notice that /coins/bitcoin is being redirected to /coins/bitcoin/ with a trailing slash (the trailing slash is an important distinction between the URLs). This is part of "url normalization" and is something that's common for hosting to do. It's unrelated to your www redirect.

The best way to fix this, in my opinion, is to make sure all your internal links are pointed at the version of the page with the trailing slash, as CloudFront is treating that version as the "canonical" version of the page. That way your users will be taken directly to the right page without needing to go through the redirect to add the slash.

Alternatively, you could play around with the treatment of trailing slashes in CloudFront settings, asking CloudFront to never redirect pages to have a trailing slash. See the AWS article Customizing the URL Format for Files in CloudFront for details. But you'll have to be careful that any relative URLs in your pages aren't broken by this, because without a trailing slash, your page's default base will be one directory up from where it would have been otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.