New

The new HostCloud is live. Web Hosting for ₹1 for your first month.

Web Hosting for ₹1 · first month

Claim offerClaim
WordPress

How to force HTTPS on WordPress: .htaccess, Nginx and plugin methods

Installing an SSL certificate is only half the job. Until you redirect every http:// request to https://, visitors and search engines can still reach the insecure version. Here are the exact rules, the common loops and how to test.

3 November 2026 · 9 min read
How to force HTTPS on WordPress: .htaccess, Nginx and plugin methods

How to force HTTPS on WordPress: .htaccess, Nginx and plugin methods

TL;DR: To force HTTPS, install a valid SSL certificate, set your WordPress Address and Site Address to https://, then add a permanent (301) redirect from HTTP to HTTPS at the server level. On Apache or LiteSpeed add a rewrite rule to .htaccess, on Nginx add a return 301 server block, and if you use Cloudflare or a proxy, make sure its SSL mode is Full and WordPress knows the original request was secure. Then fix mixed content, test with curl -I, update your sitemap and Search Console property and only then consider HSTS. A redirect loop almost always means the server or proxy and WordPress disagree about whether the request is secure.

Before you start

  1. A working SSL certificate. Visit https://yourdomain.com and confirm the browser shows a valid padlock with no warning. If it does not, fix the certificate first. See free vs paid SSL and the connection is not private error guide.
  2. A full backup. Redirect and URL changes are reversible, but a backup is cheap insurance. See how to back up WordPress properly.
  3. Know your server. Apache and LiteSpeed read .htaccess files. Nginx does not. If you are unsure, our comparison of LiteSpeed, Nginx and Apache for WordPress explains the difference.
  4. Plan for certificate renewal, so HTTPS keeps working. See setting up automatic SSL renewal and the coming shorter certificate lifetimes.

Step 1: set WordPress to HTTPS

In the WordPress admin, go to Settings, General and change both:

  • WordPress Address (URL)
  • Site Address (URL)

from http://example.com to https://example.com. Save. You will be logged out and need to log in again at the HTTPS address.

If you cannot reach the admin, set them in wp-config.php:

define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );

This makes WordPress generate HTTPS links. It does not by itself redirect visitors who request the HTTP version, so you still need Step 2.

Step 2: redirect on Apache or LiteSpeed

Add these lines near the top of the .htaccess file in your site's root folder, above the # BEGIN WordPress block:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

This sends every non-HTTPS request to the same address over HTTPS with a permanent 301 redirect. Keep a copy of the old .htaccess before editing. A typing mistake in this file can produce a 500 error. If that happens, restore the copy. See our 500 error fix guide.

If you also want to standardise www and non-www, handle both in one redirect so visitors do not pass through two hops. Decide which version you prefer, and redirect the other to it.

Flow diagram of a request to http://example.com being redirected by a 301 to https://example.com, then served by WordPress, with a check for mixed content

Step 2 alternative: redirect on Nginx

Nginx does not use .htaccess. Add a dedicated server block that listens on port 80 and redirects:

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

Your existing server block should listen on 443 with the certificate. Test the configuration and reload:

sudo nginx -t
sudo systemctl reload nginx

If you manage the server yourself, set aside time for the rest of a new server's setup, as covered in the first things to do on a new Linux VPS.

Step 2 alternative: Cloudflare and hosting panels

Hosting panels. Many control panels have a "Force HTTPS redirect" switch for each domain. It writes the redirect for you. It is the easiest method if available.

Cloudflare. Use the Always Use HTTPS setting under SSL/TLS, Edge Certificates. Set the SSL/TLS encryption mode to Full or Full (strict), which requires a valid certificate on your origin server. Do not use Flexible, which connects to your server over plain HTTP and commonly causes redirect loops on WordPress. Our guide to using Cloudflare with Indian hosting covers the setup.

Using a plugin instead

Plugins can force HTTPS and fix mixed content, which helps if you cannot edit server files. Be aware that a plugin redirects after WordPress loads, which is slower than a server-level rule, and the redirect does not apply to files WordPress does not serve. Use a server-level rule where you can, and a plugin as a fallback. Use only one method at a time, or you can create loops.

Fix mixed content

Mixed content means an HTTPS page loads some resources, such as images, scripts or stylesheets, over HTTP. Browsers block or warn about these, and the padlock may disappear.

  1. Open the page in your browser, press F12 and check the Console for "mixed content" messages.
  2. Update old URLs in your database from http:// to https://. A search-and-replace tool or WP-CLI does this safely, including serialised data:
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid --dry-run

Run it first with --dry-run, check the count, then run it again without that flag.

  1. Check theme settings, page builders and plugins that store absolute URLs.
  2. Clear all caches, including any plugin, server and CDN caches.

Fix redirect loops

An "ERR_TOO_MANY_REDIRECTS" error after forcing HTTPS means WordPress or the server keeps redirecting a request that is already secure.

Cause 1: a proxy or CDN terminates SSL. The visitor connects over HTTPS to the proxy, but the proxy talks to your server over HTTP. WordPress sees HTTP and redirects again. Fix the SSL mode to Full, and, if needed, tell WordPress to trust the forwarded header by adding this to wp-config.php above the "stop editing" line:

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
    $_SERVER['HTTPS'] = 'on';
}

Cause 2: two redirects fighting. A plugin, the host's force-HTTPS switch and .htaccess all redirect. Keep one.

Cause 3: mismatched URLs. The WordPress Address says https but a rule redirects to http, or www and non-www disagree.

Cause 4: cached redirects. Browsers cache 301s. Test in a private window.

For step-by-step diagnosis, read fixing "too many redirects" in WordPress.

Test it

After setting everything:

curl -I http://example.com
curl -I https://example.com

The first should return 301 Moved Permanently with a Location: header pointing to the HTTPS URL. The second should return 200 OK. Also test http://www.example.com and https://www.example.com, and a deep page such as /blog/some-post/, to confirm the path is preserved.

In the browser, check that the padlock shows and the Console has no mixed-content warnings.

HSTS: when to turn it on

HSTS (HTTP Strict Transport Security) tells browsers to use HTTPS for your domain for a set period, even if someone types http://. It closes a small gap in redirect-based protection, but it is hard to undo, because browsers remember the instruction for the time you set.

Turn it on only when:

  • HTTPS works on every page and subdomain you care about,
  • certificate renewal is reliable, and
  • you have tested the redirect thoroughly.

Start with a short duration, such as a few minutes or a day, and increase it gradually. Avoid the preload option unless you are sure about subdomains.

After the redirect: SEO housekeeping

Forcing HTTPS changes your URLs from a search engine's point of view. Complete the move:

  • Update your sitemap so it lists only HTTPS URLs.
  • Add the HTTPS property in Google Search Console, or use a domain property, which covers both. See Search Console verification methods compared.
  • Update canonical tags to HTTPS. See canonical tags explained.
  • Update external profiles and links you control, such as social accounts and ad destinations.
  • Check internal links use HTTPS directly, so they do not rely on redirects.

For the ranking side of the move, our guide on moving from HTTP to HTTPS without losing rankings goes into detail.

FAQs

How do I force HTTPS in WordPress?

Set the WordPress and Site Address to HTTPS, then add a 301 redirect from HTTP to HTTPS in .htaccess, in your Nginx config, in your hosting panel or through Cloudflare.

Should I use a plugin or edit .htaccess?

A server-level redirect is faster and more reliable. Use a plugin if you cannot edit server files, and use only one method.

Why do I get too many redirects after forcing HTTPS?

Usually a proxy or CDN using Flexible SSL, or two redirect rules competing. Set SSL to Full and keep a single redirect.

Does forcing HTTPS hurt SEO?

A correct 301 redirect passes ranking signals and is recommended. Make sure the sitemap, canonical tags and Search Console are updated.

What is mixed content?

An HTTPS page that loads some files over HTTP. Browsers may block them or show a warning. Update the URLs to HTTPS.

Do I need HSTS?

It is optional and best added after everything works, with a short duration at first. It is hard to reverse, so test carefully.

Does Nginx use .htaccess?

No. Nginx ignores .htaccess. Put the redirect in the server configuration instead.

How do I check that the redirect works?

Run curl -I http://yourdomain.com and look for a 301 response with a Location header pointing to the HTTPS URL.

Conclusion

Forcing HTTPS is a short sequence: valid certificate, HTTPS site URLs, one clean 301 redirect at the right layer, mixed content fixed and a quick test. Keep the redirect to a single method, be careful with proxies, and only add HSTS once everything is stable. Then update your sitemap and Search Console so search engines follow the move.

HostCloud's hosting plans include SSL, making HTTPS simple to set up and keep working. See https://hostcloud.in.

Sources:

Related posts