# RedirectRuleProperty

Struct · External

Specifies how requests are redirected.

In the event of an error, you can specify a different error code to return.

- 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 redirectRuleProperty: s3.CfnBucket.RedirectRuleProperty = {
  hostName: 'hostName',
  httpRedirectCode: 'httpRedirectCode',
  protocol: 'protocol',
  replaceKeyPrefixWith: 'replaceKeyPrefixWith',
  replaceKeyWith: 'replaceKeyWith',
};
```

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

redirect_rule_property = s3.CfnBucket.RedirectRuleProperty(
    host_name="hostName",
    http_redirect_code="httpRedirectCode",
    protocol="protocol",
    replace_key_prefix_with="replaceKeyPrefixWith",
    replace_key_with="replaceKeyWith"
)
```

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.*;

RedirectRuleProperty redirectRuleProperty = RedirectRuleProperty.builder()
        .hostName("hostName")
        .httpRedirectCode("httpRedirectCode")
        .protocol("protocol")
        .replaceKeyPrefixWith("replaceKeyPrefixWith")
        .replaceKeyWith("replaceKeyWith")
        .build();
```

C#:

```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 redirectRuleProperty = new RedirectRuleProperty {
    HostName = "hostName",
    HttpRedirectCode = "httpRedirectCode",
    Protocol = "protocol",
    ReplaceKeyPrefixWith = "replaceKeyPrefixWith",
    ReplaceKeyWith = "replaceKeyWith"
};
```

Go:

```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"

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

## Properties

- `hostName`: string — The host name to use in the redirect request.

- `httpRedirectCode`: string — The HTTP redirect code to use on the response.

  Not required if one of the siblings is present.

- `protocol`: string — Protocol to use when redirecting requests.

  The default is the protocol that is used in the original request.

- `replaceKeyPrefixWith`: string — The object key prefix to use in the redirect request.

  For example, to redirect requests for all pages with prefix `docs/` (objects in the `docs/` folder) to `documents/` , you can set a condition block with `KeyPrefixEquals` set to `docs/` and in the Redirect set `ReplaceKeyPrefixWith` to `/documents` . Not required if one of the siblings is present. Can be present only if `ReplaceKeyWith` is not provided.

  > Replacement must be made for object keys containing special characters (such as carriage returns) when using XML requests. For more information, see [XML related object key constraints](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints) .

- `replaceKeyWith`: string — The specific object key to use in the redirect request.

  For example, redirect request to `error.html` . Not required if one of the siblings is present. Can be present only if `ReplaceKeyPrefixWith` is not provided.

  > Replacement must be made for object keys containing special characters (such as carriage returns) when using XML requests. For more information, see [XML related object key constraints](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints) .
