Force all requests to HTTPS on Cloudways

I found it a little difficult to get a proper HTTPS redirect working on Cloudways. All of the other mod_rewrite rules for checking non-SSL traffic seemed to end in a redirection loop.

This turns out the be the code that works:

# HTTPS redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Put that at the start of your .htaccess  file and you should be away.

Test it first without the =301 on line 5, just in case you’ve done something wrong. Those permanent redirects will cache in your browser and can be a real pain!

Once everything looks like it’s working as it should, add the 301 back in there.

One thought on “Force all requests to HTTPS on Cloudways

Leave a Reply to Jon Cancel reply

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