2
votes

I'd like to redirect any insecure request to https, AND make sure that the url always uses 'www'. This is what I have but doesn't seem to work. What am I missing?


    Options +FollowSymLinks
    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^domain.com [NC]
    RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
    RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

2

2 Answers

3
votes

You can use:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{HTTPS} off 
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [NE,R=301,L]
0
votes
## Redirecting HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

## Redirecting non WWW to WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [R=301,L]