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]
</VirtualHost>
/var/customers/webs/cw01/wiki/data/pages/apache2/forced_redirect_https.txt · Last modified: 2012/10/12 11:15 by wadmin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki