[Apache] Redirect HTTP requests to HTTPS with .htaccess

Created on November 30, 2026

Add the following rules to an Apache .htaccess file where mod_rewrite and the relevant overrides are enabled. The condition checks whether HTTPS is off, and the rule redirects to the same host and request path over HTTPS.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
.htaccess