Hey friend! Have fun exploring Q&A, but in order to ask your own
questions, comment, or give thumbs up, you need to be logged in to your
Moz Pro account.
You can also earn access by receiving 500
MozPoints
from participating in YouMoz and the Moz Blog!

Warning about a 302 redirect

I'm testing the pro software and recently I installed an SSL Certificate on one of the websites I'm monitoring, I put in place an .htaccess directive to force all traffic to the secure version of the site (https) and I noticed how this raised a warning because my directive is forcing the traffic with a 302 redirect.

These are the lines:

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://example.com/$1 [R,L]

I understand that this is not good so I figured since I'm already redirecting all www to -www I can force traffic that arrives trying to use www to the secure version like so:

RewriteCond %{HTTP_HOST} !^example\.com$

RewriteRule (.*) https://example.com/$1 [R=301,L]

But this is not 100% effective because if someone visits the site directly on the -www version this person wont get redirected hence it wont be forced to see the https.

So my question is: does anybody know of an alternate way to force traffic to the secure socket using a 301 instead of a 302?

Oh boy, just by writing the question I think I may have figured it out, I'll post it anyways because (1) I could be wrong and (2) It could help someone else.

It just hit me but the directive that is forcing www to -www specifies what type of redirect to do here [R=301,L].

So to try to answer my own question before even posting it this could probably do the trick:

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://example.com/$1 [R=301,R,L]

I'll be testing it out ASAP and again I'll post the question anyways just in case it doesn't work, in case someone has a good suggestion or to help someone that could be in the same situation.

If this is turns out right I will need someone to slap me in the face :-|

Hey friend! Have fun exploring Q&A, but in order to ask your own
questions, comment, or give thumbs up, you need to be logged in to your
Moz Pro account.
You can also earn access by receiving 500
MozPoints
from participating in YouMoz and the Moz Blog!
Learn more.