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
1 Answer
Reset to default 0- Go to Vercel Dashboard -> Select your project.
- Navigate to Settings -> Domains.
- Find
fiziokaspars.lv
, click the three dots, and select Redirect towww.fiziokaspars.lv
. - Remove redundant redirects from next.config.ts to avoid conflicts.
本文标签: nextjsNextJS Vercel redirects issueStack Overflow
版权声明:本文标题:next.js - NextJS Vercel redirects issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741967661a2407645.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论