在Gatsby中将HTTP流量重定向到HTTPS [英] Redirect HTTP traffic to HTTPS in Gatsby

查看:113
本文介绍了在Gatsby中将HTTP流量重定向到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将HTTP流量重定向到HTTPS,因为这是PWA的Lighthouse要求.我的网站是用盖茨比建立的.

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

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

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/

对于上述插件,我尝试了以下配置,但未通过PWA审核:

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!

推荐答案

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

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

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

这篇关于在Gatsby中将HTTP流量重定向到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆