AWS ALB(Application Load Balancer)支持路径重写,可以将请求重定向到不同的目标组。以下是一个使用AWS CLI示例的解决方法:
aws elbv2 create-target-group --name my-target-group --protocol HTTP --port 80 --vpc-id your-vpc-id
aws elbv2 create-rule --listener-arn your-listener-arn --priority 1 --conditions Field=path-pattern,Values='/old-path/*' --actions Type=forward,TargetGroupArn=your-target-group-arn,ForwardConfig={TargetGroups=[{TargetGroupArn=your-target-group-arn,Weight=1}]},RedirectConfig={Path='/new-path/{path}',StatusCode='HTTP_301'}
这个示例中,请求的路径模式为/old-path/*
,将会被重写为/new-path/{path}
并进行301重定向。
请将命令中的your-vpc-id
、your-listener-arn
和your-target-group-arn
替换为你自己的值。
注意:以上示例中的命令是基于AWS CLI工具的,你需要安装并配置AWS CLI,并使用合适的访问密钥和区域。