If you are on an Apache server, then yes. One small correction, change the last line’s http: to https:. Might as well avoid another rewrite.
I actually forgot one thing.
What code do I use to redirect from https://website.com to https://www.website.com and do I add it after this code or instead of some parts of it:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
Do I use this one instead of the other one:
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
Thanks
-
This reply was modified 7 years, 12 months ago by
Jack Sarlo.
-
This reply was modified 7 years, 12 months ago by
Jack Sarlo.
I’d use the first set. The second part of the first rewrites mydomain.com to http://www.mydomain.com. Change the last line to use https though, then the order doesn’t matter too much as long as it’s before the WP rewrites.
alright but when I go to https://mysite.com it’s showing certificate error, it’s not redirecting to https://www.mysite.com.
The ssl I purchased is on https://www.mysite.com
This is the site: https://straighttalkperfectsalesletter.com/
Thanks
-
This reply was modified 7 years, 12 months ago by
Jack Sarlo.
I see. The browser triggers the warning before the redirect is able to take place. If one allowed an exception, the redirect then does indeed take place, so your rule is correct, but it’s too little too late.
A site I have also has a www common name certificate. Requesting without the www does not trigger the browser warning. Unfortunately, I do not know the specifics of the certificate, the host managed obtaining the certificate for us. Some how it works, but I could not tell you why. The site does not even have a no-www to www redirect .htaccess rule, that redirect is done by WP because the siteurl option has www. So somehow a non www request is allowed through despite the certificate’s common name having the www.
Perhaps your host could suggest what the problem may be? This issue is a little outside of WP, as it happens before WP is even involved.
I’ll contact them, the 24th time I think :).
Thanks for helping.
The basically said I have to buy ssl for the non www too.
I just figured a positive ssl from namecheap covers both www and non www. About $70 + $50 installation for 7 websites instead of $400 with a multi site ssl.
This code will redirect all to https:
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]