amazon-web-services - 无法获得正确的 URL 重定向到我的网站
问题描述
我在 NameCheap 上有自己的域名,我们称之为 example.com。我还有一个指向仅服务于 https 流量的 s3 存储桶的云端分发,我们称之为 myCloudfront.cloudfront.net
如果我去 myCloudfront.cloudfront.net 我被重定向到https://myCloudfront.cloudfront.net并且一切看起来都很好。
在 NameCheap 上,我有一条 CNAME 记录,其中包含以下值:
Type Host Value TTL
CNAME www myCloudfront.cloudfront.net Automatic
问题是我被重定向到我的云端分发的唯一方法是当我专门输入:https://www.example.com,如果我省略了 www。或尝试使用 http 它要么找不到该站点,要么因为它不是 https 而被拒绝。
如何设置 NameCheap 站点,以便如果用户键入以下任何内容,他们将被重定向到https://example.com:
example.com
www.example.com
http://example.com
http://www.example.com
https://www.example.com
谢谢!
解决方案
嗯......在我看来,在 NameCheap 中,你可以这样做:
Host Value TTL
@ your_server's_ip Automatic
www @ Automatic
因此,example.com 和 www.example.com 都将指向 example.com 服务器。
在 example.com 上,安装 Apache(我假设 example.com 是一个 Linux 服务器?),并在 /etc/httpd/conf/httpd.conf 中设置一堆 VirtualHost,以处理 http -> 之间的转发和重定向https 和 https -> cdn 等。这样的事情可能会起作用:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
Redirect https://myCloudfront.cloudfront.net/
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName www.example.com
Redirect https://myCloudfront.cloudfront.net
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@example.com
ServerName example.com
Redirect https://myCloudfront.cloudfront.net/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@example.com
ServerName www.example.com
Redirect https://myCloudfront.cloudfront.net
</VirtualHost>
如有必要,您可以通过转发和重定向获得更多创意。
上述四项规则应涵盖:
http://example.com
http://www.example.com
https://example.com
https://www.example.com
推荐阅读
- javascript - jQuery css() 不适用
- clickhouse - 计算数组中前面重复项的数量
- c# - 将 LINQ Take 和 Skip 方法与 EFCore 一起使用时的对象列表为 null
- ruby-on-rails - Params require throw 参数丢失或值为空:article
- r - 当数据中存在 NA 时,如何计算 CFA 模型的因子得分、下限和上限
- javascript - 如何在 Jasmine 中测试 Sequelize?
- abap - 将 ABAP 类型 decfloat_16 的数据插入 DF16_SCL 列时出现数据库错误
- sql-server-2012 - SQL Server 按用户 ID 分组和按日期时间透视
- html - 每个锚点都指向同一个链接
- docker - 针对服务器运行自动化测试和在服务器上运行测试之间的区别