Search code examples
rubyamazon-s3jekylljekyll-extensions

How do I add a routing rule or redirect for the root URL using the s3_website gem?


I've tried to redirect the root URL of my S3-hosted website (built in Jekyll, deployed using the s3_website gem), but haven't had any success.

My goal in the following example is to redirect http://www.example.com/ to http://www.example.com/redirect_to_here/ using s3_website's routing features.

Here are two routing rule variations I've tried without any luck:

routing_rules:
  - condition:
      key_prefix_equals: "" # Empty prefix
    redirect:
      host_name: www.example.com
      replace_key_prefix_with: redirect_to_here/
      http_redirect_code: 302

and

routing_rules:
  - condition:
      key_prefix_equals: /
    redirect:
      host_name: www.example.com
      replace_key_prefix_with: redirect_to_here/
      http_redirect_code: 302

Is this possible given S3's redirect implementation? If so, what am I missing?


Solution

  • Rather than resorting to the routing_rules and remembering that S3 treats index.html as the root path, the following ended up working. Specifically I used redirects rather than routing_rules to achieve this:

    # s3_website.yml
    redirects:
      index.html: /redirect_to_here/