Security · Guide
How to Force HTTPS in WordPress

Short answer
To force HTTPS in WordPress, install a certificate, change both site addresses in Settings, then General to https://, add a server redirect from HTTP to HTTPS, and set FORCE_SSL_ADMIN in wp-config.php. Fix mixed content and check every page loads with a padlock.
Key takeaways
- Install and test the certificate before changing any WordPress setting.
- Change both the WordPress Address and the Site Address to https:// in Settings, then General.
- Use a 301 server redirect so old HTTP links land on the HTTPS version.
- FORCE_SSL_ADMIN keeps logins and admin sessions on HTTPS; FORCE_SSL_LOGIN was deprecated in WordPress 4.0.
- Let's Encrypt certificates are free, last 90 days, and renew automatically.
What does forcing HTTPS do?
Forcing HTTPS makes every visit use an encrypted connection, so passwords, cookies, and form entries cannot be read in transit.
HTTPS is HTTP with TLS encryption, and it needs a certificate on the server to work. Without it, a visitor on the same network can read anything sent between the browser and the site, including login details.
The hardening guide calls for an HTTPS encrypted connection for admin work so all communication and sensitive data is encrypted. WordPress.org lists HTTPS support among its requirements, so a site without it is behind the standard.
Forcing HTTPS has three parts: install a certificate, switch the site addresses to HTTPS, and redirect all HTTP traffic. Each part is covered below, in that order.
How do you get an SSL certificate first?
Get a free certificate from Let's Encrypt, or switch on the free certificate your host already offers, before changing any WordPress setting.
Let's Encrypt is a free, automated, and open certificate authority run by the non-profit Internet Security Research Group. Its certificates last 90 days and renew automatically through the ACME protocol, according to the Let's Encrypt documentation.
Most managed hosts and control panels install one for you. Check the hosting dashboard for an SSL or HTTPS section before doing anything by hand, since a host certificate takes minutes and needs no commands.
On a server you manage yourself, use Certbot, the standard ACME client. The DigitalOcean guide to securing Nginx with Let's Encrypt shows the install with two commands: install Certbot with its Nginx plugin, then run sudo certbot --nginx -d example.com -d www.example.com.
The same guide notes that Certbot adds a timer that renews certificates before they expire.
Test the certificate before moving on. Open the site at https:// and confirm the padlock shows with no warning. If the browser warns, fix the certificate first, since the next steps will lock visitors into HTTPS.
How do you change the WordPress and Site addresses to HTTPS?
Open Settings, then General, and change both the WordPress Address and the Site Address from http:// to https://.
The two fields do different jobs. The WordPress Address is where the core files live, and the Site Address is the address visitors type. On most sites they match, and both must start with https://.
Follow these steps:
- Confirm the certificate works by opening the HTTPS version of the site.
- Open Settings, then General, in the dashboard.
- Change both address fields from
http://tohttps://. - Save, then log in again at the HTTPS address.
WordPress will probably sign you out when you save. That is normal, so sign back in at the HTTPS address and confirm the dashboard loads with a padlock.
If the fields are greyed out, the addresses are set in wp-config.php with WP_HOME and WP_SITEURL. The wp-config.php handbook says those constants override the database values, so edit the two lines in the file instead of the settings screen.
How do you redirect all HTTP traffic to HTTPS?
Add a redirect rule at the server so every HTTP request gets a 301 redirect to the same page on HTTPS.
Changing the addresses alone does not stop visitors arriving over HTTP. Old links, bookmarks, and search results still point at http://, so the server must send those visitors to the secure version.
On Apache or LiteSpeed, add these lines near the top of .htaccess, above the WordPress block:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
On Nginx, add a server block for port 80 that returns the same redirect, as shown in the DigitalOcean guide to securing Nginx with Let's Encrypt:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
Use a 301 redirect, not a 302. A 301 tells browsers and search engines the move is permanent, so they update their records. A plugin can do the same job, but a server rule runs before WordPress loads and is the cleaner option.
The guide to installing an SSL certificate on WordPress covers the same redirect step with screenshots for the common setups.
How do you force HTTPS for logins and the admin area?
Add define( 'FORCE_SSL_ADMIN', true ); to wp-config.php so logins and admin sessions always use HTTPS.
The wp-config.php handbook says this constant is for securing logins and the admin area so passwords and cookies are never sent in the clear. Place the line above the “That's all, stop editing!” comment, and only after the certificate works.
This constant covers sign-ins and the admin area, not the front of the site. It is a second layer behind the server redirect, and it catches any login request that somehow arrives over HTTP.
Note that WordPress deprecated the older FORCE_SSL_LOGIN constant in version 4.0, according to the same handbook page. Use FORCE_SSL_ADMIN, since the old constant no longer works.
If the site sits behind a proxy or load balancer that holds the certificate, WordPress may not see the request as secure and can loop between HTTP and HTTPS. In that case the proxy must pass the original protocol through, and the server must be set to trust it.
How do you fix mixed content warnings after the switch?
Find every image, script, and style still loaded over HTTP, and change those links to HTTPS or to relative paths.
Mixed content means a secure page loads some items over plain HTTP. Browsers block the worst of it and warn about the rest, so a page can look broken even though the certificate is fine.
The usual causes are easy to find:
- Images pasted with full
http://links in old posts. - A theme or plugin that prints
http://links for scripts or styles. - Widgets or custom HTML with hard-coded HTTP addresses.
Fix them in this order: update the post content, check the theme and widget settings, then check the plugin settings. A search-and-replace tool can update the database in one pass, but back the database up first, since a bad replace is hard to undo.
The guide to fixing mixed content warnings walks through the same checks and shows how to find the exact items a browser blocks.
Should you add an HSTS header?
Yes, once HTTPS works on every page, add a Strict-Transport-Security header so browsers refuse plain HTTP for your site.
The header tells the browser that all connections to the host must use HTTPS, according to MDN's Strict-Transport-Security page. It protects the first visit problem, where a browser that has never seen the site might still try HTTP.
Start with a short max-age while you check for problems, then raise it. MDN documents the values in seconds: 31536000 is one year and is the minimum for preload lists, while 63072000 covers two years.
Strict-Transport-Security: max-age=31536000; includeSubDomains
Add includeSubDomains only when every subdomain also serves HTTPS. A subdomain without a certificate will stop loading for visitors once the header is set, so check them first.
Do not add the header until the redirect and the mixed content fixes are done. HSTS is hard to undo quickly, since browsers remember it until the max-age runs out.
How do you check that HTTPS works on every page?
Visit the home page, a post, a category page, and the login screen, and confirm each one shows a padlock with no warning.
Run these checks after the switch:
- Open the home page over HTTPS and confirm the padlock shows.
- Open a post with images and confirm no mixed content warning appears.
- Open
http://version of the site and confirm it redirects to HTTPS. - Log in to wp-admin and confirm the dashboard stays on HTTPS.
- Run the site through an SSL checker and confirm the certificate chain is valid.
Check the login page twice, since it is the page that matters most. The guide to fixing redirect loops covers the most common failure, which is a redirect that points back to HTTP.
| Method | Where it runs | What it covers |
|---|---|---|
| Site addresses to HTTPS | Settings, then General | Links WordPress creates |
| Server redirect rule | .htaccess or Nginx config | All HTTP requests |
| FORCE_SSL_ADMIN | wp-config.php | Logins and admin area |
| HSTS header | Server response headers | Future browser visits |
All four rows work together, and none of them replaces the others. The addresses fix the links, the redirect catches old traffic, the constant guards logins, and the header guards future visits.
What should you do about search engines after the switch?
Add the HTTPS version of the site in Search Console, update the sitemap, and check that the old HTTP pages redirect instead of showing errors.
Search engines treat HTTP and HTTPS as separate addresses, so the HTTPS version needs its own record. Add it as a new property, submit the sitemap again, and confirm the old HTTP pages return a 301 redirect to their HTTPS versions.
The guide to connecting Google Search Console to WordPress shows the setup steps. Expect a short dip in reported traffic while the change settles, since the two versions are counted apart at first.
Keep the redirect in place for good. Removing it brings back the HTTP version and splits the site in two again, which is the problem the whole switch was meant to end.
Frequently asked questions
Can I force HTTPS before installing a certificate?
No. The certificate must work first. If you switch the addresses or add the redirect before the certificate is valid, browsers will warn visitors and you can lock yourself out of the admin area.
Should the redirect be a 301 or a 302?
A 301 redirect tells browsers and search engines the move is permanent, so they update their records. A 302 means temporary, so the old HTTP address stays in indexes and bookmarks.
Why does my site still show a mixed content warning?
Change the image and script links to HTTPS or to relative paths. The usual causes are old posts with full image links that still use plain HTTP, a theme or plugin printing plain HTTP links, or custom HTML with hard-coded HTTP addresses.
When should I add an HSTS header?
Only after HTTPS works on every page. The header tells browsers to refuse plain HTTP, and they remember it until the max-age runs out, so a mistake is hard to undo quickly.
Do I need to update Google Search Console after the switch?
Yes. Search engines treat HTTP and HTTPS as separate addresses, so add the HTTPS version as a new property, submit the sitemap again, and confirm the old HTTP pages return a 301 redirect.
Sources
- Let's Encrypt Resource Hub Let's Encrypt
- wp-config.php WordPress Developer Resources
- Strict-Transport-Security MDN
- Requirements WordPress.org
- How To Secure Nginx with Let's Encrypt on Ubuntu 22.04 DigitalOcean
- Hardening WordPress WordPress Developer Resources
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


