Reputation: 33
I thought I could get this accomplished using the following, but it's looping...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteCond %{HTTPS_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
What do I need to do to make sure all instances of the domain go to https://example.com without looping?
Upvotes: 2
Views: 1061
Reputation: 143906
Your first line checks if the host is what you are redirecting to. You don't need to check HTTPS_HOST
, because in https, the host is still the same (it's from the request header, Host:
).
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
Upvotes: 3