Reputation: 49
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]
Upvotes: 2
Views: 2018
Reputation: 578
## 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]
Upvotes: 0
Reputation: 18671
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]
Upvotes: 3