Skip to content

feature request: support apex redirects and www stripping redirects in request_setting #885

Open
@danbf

Description

@danbf

Terraform Version

Terraform v1.0.11
on darwin_arm64

Your version of Terraform is out of date! The latest version
is 1.9.5. You can update by downloading from https://www.terraform.io/downloads.html

Affected Fastly Terraform Resource(s)

  • fastly_service_vcl

Terraform Configuration Files

request_setting {
    force_ssl = "true"
    apex_redirect = "add_www"
  }

request_setting {
    force_ssl = "true"
    apex_redirect = "strip_www"
  }

Expected Behavior

for apex_redirect = "add_www"

sub vcl_recv {
  if (!req.http.Fastly-SSL) {
     error 801 "Force SSL";
  }
}

sub vcl_error {
  if (obj.status == 801) {
     set obj.status = 301;
     set obj.response = "Moved Permanently";
     if (req.http.Host ~ "^(?!www\.).+$") {
        set obj.http.Location = "https://www." req.http.host req.url;
      } else {
        set obj.http.Location = "https://" req.http.host req.url;
      }
     synthetic {""};
     return (deliver);
  }
}

for apex_redirect = "strip_www"

sub vcl_recv {
  if (!req.http.Fastly-SSL) {
     error 801 "Force SSL";
  }
}

sub vcl_error {
  if (obj.status == 801) {
     set obj.status = 301;
     set obj.response = "Moved Permanently";
      if (req.http.Host ~ "^www\..+?$") {
        set obj.http.Location = "https://" std.replace_prefix(req.http.Host, "www.", "") req.url;
      } else {
        set obj.http.Location = "https://" req.http.host req.url;
      }
     synthetic {""};
     return (deliver);
  }
}

Actual Behavior

currently apex_redirect is not an option and produces request_setting

sub vcl_recv {
  if (!req.http.Fastly-SSL) {
     error 801 "Force SSL";
  }
}

sub vcl_error {
  if (obj.status == 801) {
     set obj.status = 301;
     set obj.response = "Moved Permanently";
     set obj.http.Location = "https://" req.http.host req.url;
     synthetic {""};
     return (deliver);
  }
}

Debug Output (optional)

Please provide a link to a GitHub Gist containing the complete debug output (see Terraform docs). Ensure any sensitive data is <REDACTED>.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids (optional)

Adding and stripping of www. from apex redirects is common and it would be nice if Fastly's terraform did this in a single redirect rather than requiring two 301 redirects currently. A single redirect, especially for apex redirects should be better for site SEO.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions