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

HTTP:X-Forwarded-Proto for HTTPS Redirection #3

Closed
louisiscoding opened this issue Jul 19, 2019 · 3 comments
Closed

HTTP:X-Forwarded-Proto for HTTPS Redirection #3

louisiscoding opened this issue Jul 19, 2019 · 3 comments

Comments

@louisiscoding
Copy link

When using the default HTTPS redirection of this plugin, i'm facing a ERR_TOO_MANY_REDIRECTS error. This issue is referenced here.
Due to the apache services i'm using, i would need to force https with theses rules :

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

I don't succeed to write this custom rule. Can you help me ?

@AndreasFaust
Copy link
Owner

AndreasFaust commented Jul 19, 2019

Have you tries this?

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-htaccess',
      options: {
        https: false,
        custom: `
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
        `,
      },
    },
  ],
}

First disable the default https-handling (just to be sure, that there's no interference).
Then write the custom-rule into the "custom"-string, which gets appended to the .htaccess-file.

@xbojch
Copy link
Contributor

xbojch commented Aug 12, 2019

Could we add an extra flag like forward: true that in combination with https: true would generate something like

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

xbojch added a commit to xbojch/gatsby-plugin-htaccess that referenced this issue Aug 13, 2019
- adds a rewrite condition to force HTTPS also when behind a load balancer AndreasFaust#3
@louisiscoding
Copy link
Author

Awesome ! Thanks @xbojch

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

3 participants