User Tools

Site Tools


js#vista.png msort nsort


Forced redirects from http to https

I am constantly finding myself needing to do this and can never seem to remember how, so here is my little reminder on the subject.

Just a quick note. You don't actually need a port check because if you actually reach the RewriteCond then you are obviously on port 80 (so ignore all the ones on the net that say you should check for port 80. a waste of processor time). The only reason I check for HTTP_HOST is in case the VirtualHost entry below gets defaulted to as a wildcard entry. So it will only redirect on a match and error out otherwise.

<VirtualHost *:80>
    ServerName host.domain.tld
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^host\.domain\.tld$
    RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [L,R]
apache2/forced_redirect_https.txt · Last modified: 2020/02/24 11:16 (external edit)