Reputation: 125
I have redirects working for http to https, as well as canonicalization for non www URLs to redirect to WWW version…well, sort of.
http://www.domain.com redirects to https://www.domain.com
http://domain.com redirects to https://www.domain.com
https://www.domain.com loads fine
However, https://domain.com won't connect (different browsers give different messages).
I verified that mod_rewrite is enabled. Here's the code below:
#Redirect to SSL
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}[R01,L]
#Canonicalization
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1[L,R01]
Two questions:
1.) Why doesn't https://domain.com route to https://www.domain.com?
2.) I've seen the flag R=301 for redirects, but what does R01 mean?
Thanks!
Upvotes: 0
Views: 559
Reputation: 143906
You can combine the two like this:
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
A few things:
$1[L,R01]
ends up being interpreted as part of the target URL.Upvotes: 1