大网数据广告活动
网站运营与故障问答

CloudFront is 301 redirecting all my internal links

· 52CE 我爱测

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/…

问题原文

原帖链接 · Daniel Martinez · CC BY-SA 4.0

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:

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

Can someone point me in the right direction?

已采纳解答

原帖链接 · Maximillian Laumeister · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2021-08-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。