Skip to content
Koit Academy

Websites & SEO

·

7 min read

How to Redirect HTTP to HTTPS Without Losing Rankings

How to send every HTTP address to its HTTPS version in one permanent redirect, on Apache, nginx and managed hosts, and the checks that follow.

By Koit Academy

A site that works over HTTPS but still answers on plain HTTP has two copies of every page. Visitors who type the address without the s, or follow an old link, land on the insecure version, browsers warn them, and search engines see two addresses for the same content. The fix is one permanent redirect that sends every HTTP request to the same address over HTTPS.

This post covers the redirect itself on the most common setups, how to avoid chains, and the steps after the switch that keep search traffic steady.

Why it counts as a URL change

Moving from HTTP to HTTPS changes every address on the site, even though nothing else does. Google’s guidance on site moves treats a change of protocol as a move with URL changes, and the principles are the same as for any other move: map each old address to its new one, redirect permanently on the server, and update everything that points to the old addresses.

Google’s guidance on redirects prefers permanent server-side redirects for moves like this, and a 301 is the standard choice. For the difference between permanent and temporary redirects, see 301 vs 302 redirect.

Before you redirect

  1. Install a valid certificate for every hostname the site uses, including both the version with www and the one without.
  2. Check that every page works over HTTPS: open a sample of pages with https:// typed in and make sure nothing is broken.
  3. Fix mixed content. A page served over HTTPS that loads images, scripts or styles over HTTP triggers browser warnings or blocked content. Change those references to HTTPS or to relative paths.

Only then switch on the redirect. Redirecting to a broken HTTPS site is worse than not redirecting.

Apache

On Apache, the redirect usually goes in the .htaccess file at the root of the site, or in the server configuration:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The condition checks whether the request came over plain HTTP; the rule sends it to the same host and path over HTTPS with a 301. Some hosts terminate HTTPS in front of the server, in which case the condition needs to check a header the host sets instead; their documentation says which.

nginx

On nginx, a separate server block listening on port 80 does the job:

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://www.example.com$request_uri;
}

This version also chooses the hostname, sending both example.com and www.example.com straight to the www version over HTTPS in a single step.

Managed hosts and CDNs

Many managed hosting platforms and content delivery networks provide HTTPS automatically and offer a setting to always redirect HTTP to HTTPS. Where that setting exists, it is usually the simplest and most reliable option, because it runs before the request reaches your site. Check that it uses a permanent redirect and that it preserves the path and query string.

The 301 redirect generator writes individual redirect rules for Apache, nginx and hosts that use a redirects file, which helps when the HTTPS move is combined with other address changes.

Do it in one hop

The most common mistake is a chain: HTTP to HTTPS on one rule, then the non-www host to www on another, so some visitors pass through two redirects:

RequestChainedOne hop
http://example.com/page/→ https://example.com/page/ → https://www.example.com/page/→ https://www.example.com/page/
http://www.example.com/page/→ https://www.example.com/page/→ https://www.example.com/page/
https://example.com/page/→ https://www.example.com/page/→ https://www.example.com/page/

Each extra hop slows the visit and adds a step for crawlers to follow. Write the rules so every variant goes directly to the single final address, as the nginx example does.

After the switch

The redirect is only half the job. Everything that refers to the old addresses should be updated to the new ones, so visitors and crawlers reach them directly rather than through the redirect:

  • Internal links, in menus, footers and page content.
  • Canonical tags, which should point to the HTTPS addresses.
  • The sitemap, which should list only HTTPS addresses. The XML sitemap generator rebuilds it from a list.
  • The sitemap line in robots.txt, if it gives the full address.
  • Structured data, Open Graph tags and hreflang annotations that contain full addresses.
  • Profiles and listings you control: the Business Profile, social profiles and directories.

Search Console

Search Console treats HTTP and HTTPS as separate properties unless you use a domain property, which covers every protocol and subdomain. If you use URL-prefix properties, add the HTTPS version so you can see its data, and submit the new sitemap there. Expect the pages to move from the old addresses to the new ones in reports over the following weeks.

Testing the redirect

Check a handful of addresses in every form: http and https, with and without www, the home page and a deep page with a query string. Each should end at the single preferred HTTPS address in one step, with a 301 status, keeping the path and query intact. Browser developer tools show the status code and every hop.

Also confirm that robots.txt on the HTTPS site allows what it should; it is a separate file from the HTTP one as far as crawlers are concerned. The robots.txt tester checks a list of addresses against it.

HSTS, once everything works

HTTP Strict Transport Security is a response header that tells browsers to use HTTPS for your site automatically for a set period, without even trying HTTP first. It closes the gap that a first insecure request leaves open. Add it only once HTTPS works reliably across the whole site, start with a short duration, and lengthen it once you are sure, because browsers will refuse HTTP for the site for as long as the header says.

What to expect afterwards

A move from HTTP to HTTPS done properly usually causes little disruption, because nothing changes for visitors except the padlock. In search, Google’s guidance on site moves warns that rankings can fluctuate for a while during any move as the new addresses are processed. Watch Search Console’s reports over the following weeks: the HTTPS addresses should take over from the HTTP ones in the indexing and performance reports, and the number of indexed HTTP pages should fall.

Keep the redirects in place permanently. Old links on other sites, bookmarks and printed material will keep sending people to HTTP addresses for years, and each of those visits needs the redirect.

Moving several things at once

Some site moves change the protocol, the hostname and the structure of the addresses at the same time. Each change on its own is manageable; together they multiply the chances of a mistake. Where possible, move to HTTPS first, on its own, and change the structure later. If they must happen together, map every old address to its final new address directly, so no visitor or crawler passes through an intermediate step.

Checking every hostname

It is easy to fix the main hostname and forget the others: the version without www, an old domain that still points at the site, a subdomain used for a campaign. List every hostname that resolves to your server and check each one, over both HTTP and HTTPS. Every one should end at the preferred address in a single permanent redirect.

Forms, payments and third-party services

Before switching on the redirect, check everything that sends data to or from the site: contact forms, booking widgets, payment pages, webhooks and integrations with other services. Some store the site’s address and keep posting to the HTTP version, which may then redirect and lose the submitted data. Update the stored addresses in each service, and submit a test form after the switch to make sure it still arrives.

Images, scripts and fonts from other services

Resources loaded from other services, such as fonts, maps, video embeds and analytics scripts, also need HTTPS addresses. Most providers have offered HTTPS for years, so the fix is usually changing http to https in the embed code. A resource that is only available over HTTP has to be replaced, because browsers will block it or warn about it on a secure page. Check the browser console on a few key pages after the switch; mixed content warnings appear there.

HTTPS redirect mistakes

  • Temporary redirects instead of permanent ones.
  • Redirecting everything to the home page instead of to the same page over HTTPS.
  • Chains between protocol and hostname rules.
  • Dropping the query string, which breaks tracked and filtered links.
  • Leaving internal links, canonicals and the sitemap on HTTP.

Sources, read November 14, 2026:

  • Google Search Central, Site moves with URL changes: a change of protocol as a site move, mapping old to new URLs, permanent server-side redirects, and updating internal links and sitemaps.
  • Google Search Central, Redirects and Google Search: permanent server-side redirects for moves.