Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a site that I have redirecting to HTTPS. I do this to leverage wildcard SSL for my password protected pages. Everything seems to work fine with testing. For example, whether you type in HTTP or www, you always get redirected to the SSL HTTPS...

That said, I have about 200-300 external backlinks -- many high quality, yet Google Webmaster (along with SEOMoz), shows I have just 4... Huh? I'm embarrassed to say I just discovered this. This has led me to hypothesize that maybe my settings in .htaccess is messed up, so Google isn't recognizing a link because it's recorded on another site as HTTP, instead of HTTPS. Maybe? At any rate, here is my simple .htaccess setting for 301 www to HTTP, and from HTTP to HTTPS.

RewriteCond %{SERVER_PORT} !443
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

Like I said, everything works fine for redirect over HTTPS, so I'd rather not screw up what works. On the other hand something is very wrong with Google finding all my back links, so I need to fix something... I'm just wondering that maybe Google isn't picking up a my backlinks from other websites recording me as HTTP because I'm at HTTPS. Maybe Google doesn't care and it's some other issue. Am I barking up the right tree? If so any quick fixes?

share|improve this question
1  
"whether you type in http or www, you always get redirected to the SSL https" - What you have posted does not appear to do this? This code simply redirects to the non-www version of the domain, but keeps the protocol as HTTP or HTTPS. I can't see how it redirects from HTTP to HTTPS? –  w3d Dec 14 '12 at 22:43
    
Thanks, the second rule above redirects to https. And it does work. But it sounds like you think this should be written differently, perhaps in a way that doesnt confuse google. Any suggestions? Again, i'm looking for a redirect that pushes everyone to https. That includes those that link to http and www, which is what this htaccess rule was trying to accomplish. Thoughts? –  user20680 Dec 14 '12 at 23:38
add comment

1 Answer 1

Sorry about logging in as a different user. Still new here. I didn't think this site was affiliated to the other site. Thanks for adding a loop between the two sites. How about an answer for people. These 301s seem to have many ways of solving this and it can get confusing. I had a special use-case trying to do two things in one shot >> redirect all http://www.example.com & http://example.com over to https://example.com.

This worked like a charm for me. These two conditions play nicely.

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.