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"
Written by Jose Alb. Hernandis
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#N
Authors
Related Tags
#n
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#