Reputation: 411
For a long time we have had our site running without www in front, but we have recently been forced to make a change.
We recently changed from domainhere.com to www.domainhere.com. We already had a redirect from http to https, but need to change the redirect from https://domainhere.com to https://www.domainhere.com.
We used this code. How do we make it still redirect to HTTPS but with www in front?
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.skarpeknive.dk/$1 [R,L]
We found this on Stackoverflow, but it doesn't seem to work. The site bugs on domainhere.com then
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 2
Views: 50
Reputation: 4302
Maybe there is proxy issue so,try this :
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Note: clear browser cache then test
Upvotes: 1