Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect HTTP traffic to HTTPS in Gatsby

Tags:

reactjs

gatsby

I would like to redirect HTTP traffic to HTTPS as this is a Lighthouse requirement for PWAs. My site is built with Gatsby.

I found various plugins like the ones below which seem to imply that the answer comes from modifying the .htaccess file.

https://www.gatsbyjs.org/packages/gatsby-plugin-htaccess/

For the plugin above, I tried the following configuration, which didn't pass the PWA audit:

{
      resolve: 'gatsby-plugin-htaccess',
      options: {
        RewriteBase: '/custom/',
        https: true,
        www: true,
        SymLinksIfOwnerMatch: true,
        host: 'av-site.com',
        redirect: [
          'RewriteRule ^not-existing-url/?$ /existing-url [R=301,L,NE]',
          {
            from: 'http:av-site.com',
            to: 'https:av-site.com',
          },
        ],
      },
    },

Can anyone please help me? Thanks!

like image 890
Alex Verzea Avatar asked Sep 18 '26 13:09

Alex Verzea


1 Answers

Make sure in gatsby-config.js the siteURL is https

module.exports = {
  siteMetadata: {
    title: `example`,
    description: ``,
    author: `me`,
    siteUrl: `https://example.com`
  },
like image 120
Nicholas Cappello Avatar answered Sep 20 '26 04:09

Nicholas Cappello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!