我正在与Google Search Console遇到问题,说我的主页上有太多重定向。因此,基本上,我希望重定向发生到-http和non -www,这意味着我希望两者都成为

问题描述 投票:0回答:1
C:\Users\user>curl -I -L http://fiziokaspars.lv HTTP/1.0 308 Permanent Redirect Content-Type: text/plain Location: https://fiziokaspars.lv/ Refresh: 0;url=https://fiziokaspars.lv/ server: Vercel HTTP/1.0 301 Moved Permanently Cache-Control: public, max-age=0, must-revalidate Content-Type: text/plain Date: Thu, 30 Jan 2025 11:55:06 GMT Location: https://www.fiziokaspars.lv/ Server: Vercel Strict-Transport-Security: max-age=63072000 X-Vercel-Id: arn1::gftqt-1738238106226-4955f86f010f HTTP/1.0 200 OK Accept-Ranges: bytes Access-Control-Allow-Origin: * Age: 207 Cache-Control: public, max-age=0, must-revalidate Content-Disposition: inline Content-Length: 73664 Content-Type: text/html; charset=utf-8 Date: Thu, 30 Jan 2025 11:55:06 GMT Etag: "b9b44a87d39dce2c6f55095eb3a12c91" Server: Vercel Strict-Transport-Security: max-age=63072000 Vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Router-Segment-Prefetch X-Matched-Path: / X-Nextjs-Prerender: 1 X-Nextjs-Stale-Time: 4294967294 X-Vercel-Cache: HIT X-Vercel-Id: arn1::vqq6x-1738238106385-30dc64cd9508

首先,从http://fiziokaspars.lv

https://fiziokaspars.lv
,然后再到

https://www.fiziokaspars.lv
。如何防止第一次重定向并仅使用1重定向进行操作?因为这与我的Google搜索控制台混乱了。
Mynext.config.ts文件:

import { NextConfig } from 'next'

const config: NextConfig = {
  async redirects() {
    return [
      // Redirect from non-www HTTP to HTTPS www
      {
        source: '/:path*', // Capture all paths
        has: [
          {
            type: 'host',
            value: 'fiziokaspars.lv',
          },
        ],
        destination: 'https://www.fiziokaspars.lv/:path*', // Redirect to the www version
        permanent: true,
      },
      // Redirect from non-www HTTPS to www
      {
        source: '/:path*',
        has: [
          {
            type: 'host',
            value: 'fiziokaspars.lv',
          },
        ],
        destination: 'https://www.fiziokaspars.lv/:path*', // Redirect to the www version
        permanent: true,
      }
    ]
  }
}

export default config
	
到达Vercel仪表板 - >选择您的项目。

驱动到设置 - >域。

找到fiziokaspars.lv,单击三个点,然后选择重定向到

www.fiziokaspars.lv
.
从Next.config.ts避免冲突的冗余重定向。
next.js vercel
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.