Force HTTPS for WordPress Installations

Just add this snippet to the beginning of your rewrite section of your .htaccess file to force HTTPS:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]



# END WordPress

As you can see, I placed it directly under “RewriteEngine On”.

Or you can also  use this Snippet to force HTTPS for your application:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

Force HTTPS behind a proxy

If you are behind a proxy or a FPC (Varnish f.e.), you have to change the rewrite condition as shown below to force HTTP:

RewriteCond %{HTTP:X-Forwarded-Proto} !https

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.