# RoutingRuleProperty

Specifies the redirect behavior and when a redirect is applied.

For more information about routing rules, see [Configuring advanced conditional redirects](https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html#advanced-conditional-redirects) in the *Amazon S3 User Guide* .

- Source: Generated at build time
- Type last changed: v2.93.0 · 23 Aug 2023

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_s3 as s3 } from 'aws-cdk-lib';
const routingRuleProperty: s3.CfnBucket.RoutingRuleProperty = {
  redirectRule: {
    hostName: 'hostName',
    httpRedirectCode: 'httpRedirectCode',
    protocol: 'protocol',
    replaceKeyPrefixWith: 'replaceKeyPrefixWith',
    replaceKeyWith: 'replaceKeyWith',
  },

  // the properties below are optional
  routingRuleCondition: {
    httpErrorCodeReturnedEquals: 'httpErrorCodeReturnedEquals',
    keyPrefixEquals: 'keyPrefixEquals',
  },
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_s3 as s3

routing_rule_property = s3.CfnBucket.RoutingRuleProperty(
    redirect_rule=s3.CfnBucket.RedirectRuleProperty(
        host_name="hostName",
        http_redirect_code="httpRedirectCode",
        protocol="protocol",
        replace_key_prefix_with="replaceKeyPrefixWith",
        replace_key_with="replaceKeyWith"
    ),

    # the properties below are optional
    routing_rule_condition=s3.CfnBucket.RoutingRuleConditionProperty(
        http_error_code_returned_equals="httpErrorCodeReturnedEquals",
        key_prefix_equals="keyPrefixEquals"
    )
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.s3.*;

RoutingRuleProperty routingRuleProperty = RoutingRuleProperty.builder()
        .redirectRule(RedirectRuleProperty.builder()
                .hostName("hostName")
                .httpRedirectCode("httpRedirectCode")
                .protocol("protocol")
                .replaceKeyPrefixWith("replaceKeyPrefixWith")
                .replaceKeyWith("replaceKeyWith")
                .build())

        // the properties below are optional
        .routingRuleCondition(RoutingRuleConditionProperty.builder()
                .httpErrorCodeReturnedEquals("httpErrorCodeReturnedEquals")
                .keyPrefixEquals("keyPrefixEquals")
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.S3;

var routingRuleProperty = new RoutingRuleProperty {
    RedirectRule = new RedirectRuleProperty {
        HostName = "hostName",
        HttpRedirectCode = "httpRedirectCode",
        Protocol = "protocol",
        ReplaceKeyPrefixWith = "replaceKeyPrefixWith",
        ReplaceKeyWith = "replaceKeyWith"
    },

    // the properties below are optional
    RoutingRuleCondition = new RoutingRuleConditionProperty {
        HttpErrorCodeReturnedEquals = "httpErrorCodeReturnedEquals",
        KeyPrefixEquals = "keyPrefixEquals"
    }
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

routingRuleProperty := &RoutingRuleProperty{
	RedirectRule: &RedirectRuleProperty{
		HostName: jsii.String("hostName"),
		HttpRedirectCode: jsii.String("httpRedirectCode"),
		Protocol: jsii.String("protocol"),
		ReplaceKeyPrefixWith: jsii.String("replaceKeyPrefixWith"),
		ReplaceKeyWith: jsii.String("replaceKeyWith"),
	},

	// the properties below are optional
	RoutingRuleCondition: &RoutingRuleConditionProperty{
		HttpErrorCodeReturnedEquals: jsii.String("httpErrorCodeReturnedEquals"),
		KeyPrefixEquals: jsii.String("keyPrefixEquals"),
	},
}
```

## Properties

- `redirectRule`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnBucket.RedirectRuleProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.CfnBucket.RedirectRuleProperty.html) (required) — Container for redirect information.

  You can redirect requests to another host, to another page, or with another protocol. In the event of an error, you can specify a different error code to return.

- `routingRuleCondition`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnBucket.RoutingRuleConditionProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.CfnBucket.RoutingRuleConditionProperty.html) — A container for describing a condition that must be met for the specified redirect to apply.

  For example, 1. If request is for pages in the `/docs` folder, redirect to the `/documents` folder. 2. If request results in HTTP error 4xx, redirect request to another host where you might process the error.
