Best .htaccess Rules to Force HTTPS in WordPress

Best .htaccess Rules to Force HTTPS in WordPress

A valid certificate at the origin does not guarantee a safe force-HTTPS rule. Behind a CDN or reverse proxy, Apache and the edge may disagree about the original scheme and redirect the same request repeatedly.

Prepare TLS and WordPress URLs first, decide which layer owns the redirect, and use request information that is trustworthy in that architecture.

Table of contents

  1. What it means
  2. A realistic WordPress example
  3. Why it matters and when to use it
  4. A straightforward route for beginners
  5. The advanced route
  6. Risks, common mistakes, backup, and rollback
  7. How AIOWS helps: AIOWS Htaccess Editor
  8. Related AIOWS articles
  9. Conclusion and recommended route
  10. Official sources

What it means

An HTTPS redirect sends an HTTP request to the same canonical resource over HTTPS. It does not install a certificate, repair mixed content or make an insecure origin connection safe.

When a trusted proxy terminates TLS, the origin may see HTTP even for a secure visitor request. The redirect condition must account for the approved proxy signal or be owned by the edge instead.

A realistic WordPress example

A CDN serves HTTPS publicly but connects to Apache over HTTP. A copied rule checks only the origin scheme, so Apache redirects every proxied request to the URL the visitor already requested.

The team chooses the CDN as the sole redirect owner, configures a secure origin mode and removes the competing Apache rule. WordPress home and site URLs remain HTTPS.

Why it matters and when to use it

A single secure canonical URL protects traffic and simplifies cookies, caches, analytics and search signals. Forcing it is appropriate only when all public hostnames have valid certificate coverage and the application works over HTTPS.

Resolve mixed-content and callback issues before considering stricter policies such as HSTS, which can make a faulty rollout harder to reverse in browsers.

A straightforward route for beginners

  1. Verify certificate names, chain and expiry for every public hostname.
  2. Confirm that pages, admin, assets and callbacks work directly over HTTPS.
  3. Set the WordPress Address and Site Address to the final secure URLs.
  4. Choose the CDN, web server or WordPress as the only redirect owner.
  5. Test HTTP and HTTPS requests while following every status and Location header.
  6. Check mixed content, sign-in, forms and transactions before removing the old configuration.

The advanced route

At a proxy, trust forwarded scheme headers only from known intermediaries and confirm the configured TLS mode. Client-supplied headers must not be accepted as proof of HTTPS.

Use one direct hop to the canonical host and path, preserve required queries and avoid rules inside the WordPress-managed block. Inspect origin and edge logs when the public trace differs from a direct-origin control.

Risks, common mistakes, backup, and rollback

Competing redirects can loop, and an invalid certificate prevents the browser from reaching any rule. Flexible or partially encrypted proxy modes can also create a false impression of end-to-end security.

Save the former server, edge and WordPress settings as one rollback set. Delay HSTS until the secure route is stable, because removing a header does not immediately remove a cached browser policy.

How AIOWS helps:

AIOWS Htaccess Editor

AIOWS Htaccess Editor can manage a supported Apache-side HTTPS rule when .htaccessis the chosen redirect owner. Keeping the change visible helps distinguish it from WordPress permalink directives.

Back up the file, place custom logic outside WordPress markers and test through the actual proxy path. The rule should recognize the effective scheme correctly and send one hop to the final host.

The editor cannot provision certificates, secure a proxy-to-origin connection or establish trust for forwarded headers. If the CDN owns HTTPS canonicalization, configure it there and avoid a duplicate rule in .htaccess.

Explore AIOWS Htaccess EditorCompare AIOWS plans

Conclusion and recommended route

Force HTTPS only after the secure route works, let one layer own the redirect and account for trusted proxies explicitly. A direct verified hop is better than several rules that happen to agree in one test.

Official sources

Related Posts

Get All in One WP SettingsGet Plugin