reactjs - 在 Gatsby 中将 HTTP 流量重定向到 HTTPS

标签 reactjs gatsby

我想将 HTTP 流量重定向到 HTTPS,因为这是 PWA 的 Lighthouse 要求。我的网站是用 Gatsby 构建的。

我发现了各种插件,例如下面的插件,它们似乎暗示答案来自于修改 .htaccess 文件。

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

对于上面的插件,我尝试了如下配置,没有通过PWA审核:

{
      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',
          },
        ],
      },
    },

谁能帮帮我?谢谢!

最佳答案

确保 gatsby-config.js 中的 siteURL 是 https

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

关于reactjs - 在 Gatsby 中将 HTTP 流量重定向到 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57044036/

相关文章:

reactjs - 从 react 路由器迁移到 react 路由器 v6

javascript - 是否可以使用 Gatsby 进行推送通知?

javascript - Gatsby JS - 多个页面拉入不同类别的 Markdown 文件

reactjs - 为什么 "import { React } from ' react ';“不起作用?

javascript - react 组件中的状态不会呈现

laravel - 结合 Laravel 和 Create-React-App

javascript - 如何从类组件更新功能组件的状态,以便在 react 中显示 map 中的项目

reactjs - 当我使用 react Hook 单击按钮时如何更改背景颜色

reactjs - Material-ui中隐藏组件,如何防止渲染?

graphql - Gatsby 在 graphql 获取时的构建过程中给出错误 "Error: Type with name "File"does not exists"