PHPnews.io

Apache .htaccess enforce HTTPS

Written by Bram.us / Original link on Feb. 15, 2021

apache-http-server-header.png

Because I have to look this up from time to time, a note to myself: Add the contents below to your .htaccess to have Apache enforce HTTPS while preserving the rest of the URL (domain name, querystring, etc).

RewriteEngine On

# Enforce HTTPS (everywhere)
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

~

Did this help you out? Like what you see?
Thank me with a coffee.

I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

☕️ Buy me a Coffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

bram bram calevans sitepoint bram

« Apache .htaccess trim www. prefix from domain name - Free Early Bird Registration for SPOTcon 2021 Now Open »