Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
danbf opened this issue Sep 27, 2024 · 0 comments

Comments

@danbf
Copy link

danbf commented Sep 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant