Redirect HTTP traffic to HTTPS in Gatsby

笑着哭i 提交于 2020-03-05 04:22:50

问题


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!


回答1:


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

module.exports = {
  siteMetadata: {
    title: `example`,
    description: ``,
    author: `me`,
    siteUrl: `https://example.com`
  },


来源:https://stackoverflow.com/questions/57044036/redirect-http-traffic-to-https-in-gatsby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!