1

I know there are many posts on redirects, and I've read a lot of them now, but only a few that I've found seem to touch on what I need and often seem to contain conflicting information

I need to get:

http://example.com -> https://www.example.com
http://www.example.com -> https://www.example.com

and more importantly:

https://example.com -> https://www.example.com

I can find many solutions to the first two. Like this one:

#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]

or this one:

RewriteEngine on

RewriteCond %{REQUEST_SCHEME} http [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]

These rules look like what I should be after, but I've only got a certificate that covers https://www.example.com. Is the third redirect possible? (https://example.com to https://www.example.com). The answers in the question I linked seem to suggest it might be possible without another certificate, but there's disagreement.

I would have thought that there's no way around the problem, but I'm hoping there can be and would appreciate input.

*edit: if I don't get a certificate for https://example.com, it won't be classed as a duplicate by search engines will it?

NickW
  • 1,207
  • 1
  • 12
  • 52

1 Answers1

1

To do a redirect between subdomains (* -> www), you need a certificate for each domain that runs https, or you need a wildcard certificate that handles them all.

The redirect is a completely separate issue.

Once you get a valid connection, you can redirect or not.

If the connection isn't valid (wrong/missing ssl cert), the redirect will never happen.

Terry Carmen
  • 3,720
  • 1
  • 16
  • 32
  • yeah, that's basically the answer I came to, but like I said a few people gave me a tiny bit of hope. I've made a slight edit to the question at the end - if I don't have a cert for that domain, will it be classed as a duplicate by search engines? – NickW May 23 '18 at 18:49
  • The cert has nothing to do with being a duplicate. It's strictly to enable HTTP over SSL. If you want to make sure you don't get dinged for a duplicate domain, make sure you use an HTTP 301 (moved permanently) redirect on the domain that does NOT contain your content. This prevents google from thinking you're putting up redundant identical sites. – Terry Carmen May 23 '18 at 18:57
  • 1
    Always happy to help! I'm on a personal mission to make SO friendlier. 8-) – Terry Carmen May 24 '18 at 01:11