admin管理员组

文章数量:1314554

I am having an issue with Google Search Console saying that there are too many redirects on my homepage. So basically, I want the redirect to happen to both - http and non-www, it means i want both to be . So i want both https AND www. But right now, when i enter curl -I -L , i get double redirect:

C:\Users\user>curl -I -L 
HTTP/1.0 308 Permanent Redirect
Content-Type: text/plain
Location: /
Refresh: 0;url=/
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: /
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

First, from to , and then to . How can i prevent the first redirect and do it with 1 redirect only? Cause this messes up with my google search console.

My next.config.ts file:

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: '/:path*', // Redirect to the www version
        permanent: true,
      },
      // Redirect from non-www HTTPS to www
      {
        source: '/:path*',
        has: [
          {
            type: 'host',
            value: 'fiziokaspars.lv',
          },
        ],
        destination: '/:path*', // Redirect to the www version
        permanent: true,
      }
    ]
  }
}

export default config

This is my domains page in vercel:

I am having an issue with Google Search Console saying that there are too many redirects on my homepage. So basically, I want the redirect to happen to both - http and non-www, it means i want both to be https://www.fiziokaspars.lv. So i want both https AND www. But right now, when i enter curl -I -L http://fiziokaspars.lv, i get double redirect:

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

First, from http://fiziokaspars.lv to https://fiziokaspars.lv, and then to https://www.fiziokaspars.lv. How can i prevent the first redirect and do it with 1 redirect only? Cause this messes up with my google search console.

My next.config.ts file:

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

This is my domains page in vercel:

Share Improve this question edited Jan 30 at 12:24 kasparinho asked Jan 30 at 11:59 kasparinhokasparinho 112 bronze badges 2
  • You shouldn't need to add redirects for https, vercel does this automatically. For www redirects, you can set the domain in vercel (which you've done according to the screenshot). – Reyno Commented Jan 30 at 12:29
  • @Reyno cleared my next.config.ts, there are no more additional redirects, only the one from the vercel/domains screenshot. But still it gives me double redirect that messes up with google seo. Maybe I need to change the Status Code for the redirect in Vercel for fiziokaspars.lv? – kasparinho Commented Jan 30 at 13:01
Add a comment  | 

1 Answer 1

Reset to default 0
  1. Go to Vercel Dashboard -> Select your project.
  2. Navigate to Settings -> Domains.
  3. Find fiziokaspars.lv, click the three dots, and select Redirect to www.fiziokaspars.lv.
  4. Remove redundant redirects from next.config.ts to avoid conflicts.

本文标签: nextjsNextJS Vercel redirects issueStack Overflow