Redirects from http www to non-www on HTTPS

Hello Vercel Community,

I am currently trying to optimize my URL redirects to enhance SEO and user experience by minimizing redirect chains on my site hosted with Vercel and built with Next.js. I am experiencing some issues with how redirects are currently handled and need help configuring them correctly.

Current versus Expected behavior

Current Behaviour

Using the httpstatus.io tool, I’ve noticed that my domain’s HTTP requests undergo multiple redirects before reaching the final HTTPS non-www URL, which is not optimal. Here’s what happens when I test http://www.example.com:

  1. http://www.example.com redirects to https://www.example.com (Status 308)
  2. https://www.example.com then redirects to https://example.com (Status 308)

This behavior results in two redirect steps as illustrated in the screenshot below:

Here, by default, HTTP redirects directly to the HTTPS domain.

Expected Behaviour

I would prefer that any access to http://www.example.com redirects directly to https://example.com in a single step using a 301 status code for all redirects. This adjustment is crucial for maintaining link equity and SEO ranking. Here’s the behavior I aim for:

  • Single redirect from any www version directly to the non-www HTTPS version with a 301 status code. The current setup uses a 308 status code

Challenges and Configuration Attempts

According to Vercel’s documentation, it is possible to define HTTP redirects within an application (screenshot attached). But have been unable to configure the desired behavior.

According to Vercel’s documentation, it should be possible to define such redirects. I attempted to use the following configuration in my vercel.json:

However, this resulted in a ‘too many redirects’ error. Below is a snippet from the Vercel documentation I referenced: Configuring projects with vercel.json

{
  "redirects": [
    {
      "source": "/(.*)",
      "destination": "https://example.com",
      "statusCode": 301 
    }
  ]
}

Documentation and Resources Consulted

Previous Community Post Found

I found a similar issue discussed here: Community Post, but it lacks a conclusive solution, which is why I am reaching out for additional insights.

Project information (URL, framework, environment, project settings)

  • Nextjs v15.1.7
  • WordPress API
  • vercel (Hobby Version)

Thank you in advance for your help!

The domain troubleshooting guide can help with most custom domain configuration issues. You might be able to use that guide to solve it before a human is available to help you. Then you can come back here and share the answer for bonus points.

You can also use v0 to narrow down the possibilities.

I’ve already reviewed this.

Hi @syedamahamfahim, welcome to the Vercel Community!

I understand your concern. But I’d like to share with you that according to Vercel’s Encryption method, all requests coming to http are first redirected to https and then all the other rules are applied. So, the 2 redirects is how it works.

About using 301 instead of 308, you can set that from the Domains settings:

May I know the exact issue that you are facing due to this?

1 Like

Hi Anshuman, thanks for getting back to me. I understand the concept of two redirects. Regarding the 301 status, I’ve changed it from the dashboard, but it’s only affecting HTTPS. For HTTP, it still shows a 308 status. The documentation mentions that HTTP passes through a 308 status. Is there a way to configure HTTP to use a 301 status instead?

If it’s just an SEO concern, 308 is identical to 301 for GET requests and only differs on POST requests, so there is no difference to SEO between them.

Some old clients have unexpected behavior on POST requests with 301/302 codes (often turning into GET requests) so 308/307 were created as the modern replacements.

1 Like

Thanks Jacob, i understood.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.