我想将我的根域重定向到www.domain.com。该网站使用s3 CloudFront和route53发布。
我看过很多关于如何使用s3重定向的文档,但是我不能这样做,因为在某个地方已经有一个我的根域的存储桶了。所以我不能创建一个以我的根域作为名称的存储桶。此外,我怀疑此s3重定向是否适用于https请求。
我还没有看到任何关于不使用s3存储桶进行重定向的博客。
那么,如何在aws中将HTTP/https根域重定向到www子域。
发布于 2020-07-24 19:17:00
您不能使用Route 53进行重定向(它毕竟是DNS配置服务,而重定向是HTTP操作)。
如果不能使用S3,另一种解决方案是将CloudFront与Lambda@Edge函数一起使用。
如果主机名不是www域,则可以对www域执行redirect。
该函数可能如下所示
def lambda_handler(event, context):
request = event["Records"][0]["cf"]["request"]
response = event["Records"][0]["cf"]["response"]
# Generate HTTP redirect response with 302 status code and Location header.
if request['headers']['host'][0]['value'] != 'www.example.com':
response = {
'status': '302',
'statusDescription': 'Found',
'headers': {
'location': [{
'key': 'Location',
'value': 'https://www.example.com/{}' .format(request['uri'])
}]
}
}
return responsehttps://stackoverflow.com/questions/63072430
复制相似问题