Skip to content

Route /images to an S3 Bucket

Route requests with a URI path starting with /images to a specific AWS S3 bucket using Cloud Connector.

To route requests to /images on your domain to an AWS S3 bucket:

  1. Log in to the Cloudflare dashboard and select your account and domain.
  2. Navigate to Rules > Cloud Connector.
  3. Select Amazon Web Services - S3 as your cloud provider.
  4. Enter the bucket URL. You can structure this in two ways:
    • Subdomain-style URL: Set the hostname to <BUCKET_NAME>.s3.amazonaws.com. In this case, your files should be organized in the root of the bucket, meaning the URI path will map directly to the file. For example, https://<YOUR_HOSTNAME>/images/file.jpg will map to https://<BUCKET_NAME>.s3.amazonaws.com/images/file.jpg.
    • URI path-style URL: Set the hostname to s3.amazonaws.com. Here, your bucket must include a folder named images, and files should be placed inside this folder. The URI path will then include the bucket name, like https://<YOUR_HOSTNAME>/<BUCKET_NAME>/images/file.jpg mapping to https://s3.amazonaws.com/<BUCKET_NAME>/images/file.jpg.
  5. (Optional) Use the Rewrite URL feature of Transform Rules to adjust the URL structure. For example, you can create a URL rewrite that changes /images to /<BUCKET_NAME>/images to match the URI path-style URL structure.
  6. Click Next and enter a descriptive name like “Route images to S3” in Cloud Connector name.
  7. Under If, select Custom filter expression and enter the following expression: http.request.full_uri wildcard "https://<YOUR_HOSTNAME>/images/*"
    Replace <YOUR_HOSTNAME> with desired hostname.
  8. Select Deploy to activate the rule.

This setup will route all traffic to https://<YOUR_HOSTNAME>/images/* directly to your S3 bucket. Make sure to replace <YOUR_HOSTNAME> with your actual hostname and adjust the example paths according to your setup.