Last Updated: September 09, 2019
·
491
· jhernandis

htaccess redirect to www and SSL

If you want to redirect from http://domain.com to https://www.domain.com this is the .htaccess you should use:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# first redirect to www.
RewriteCond %{http_host} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

# second redirect to SSL
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

You must do in that order if the certificate was for "www.domain.com"