Htaccess, the right way to enable HTTPS (on www site)?

6 replies
I have read a lot and spent a lot of hours trying to reach the right way to set a good htaccess in order to redirect an HTTP site to HTTPS.

There are a lot of tutorials on the Internet, but some of them seem to be outdated and don't meet good SEO practices.

The scenario is the following one:

My site has Cloudflare enabled
My site has a valid SSL on server-side
The current htaccess of my site:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^MYSITE\.cl$
RewriteRule ^(.*) http://www.MYSITE.cl/$1 [R=301]
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
and I want to change .htaccess in order to keep my good SEO rank on Google, use the HTTPS and keep the .WWW:

#OLD PART
RewriteEngine On
RewriteBase /

# Non-www to www (NEW PART)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]

# Non-SSL to SSL (NEW PART)
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

#OLD PART AGAIN
RewriteRule ^/?find$ find.php [L]
RewriteRule ^/?do$ do.php [L]
ErrorDocument 404 /404.html
Options -Indexes
Will this work well? Do you have a better idea? Does my code have any redundancy? I think that I must set Cloudflare SSL parameters to FULL SSL (STRICT). Is that right?
#enable #htaccess #https #site #www
Avatar of Unregistered
  • Profile picture of the author whitehat
    Have you talked with your web hosting rep yet? I answered my htaccess question with mine, a few months back.

    They told me what I was trying to do [w/ speeding up my site] could not be done. So now my site's speed is only 99% faster than others instead of being 100%.

    [I'm just waiting a few more months, to work on it again. Hopefully server software and or new procedures will make what I was trying to do work.]
    Signature
    {{ DiscussionBoard.errors[11349785].message }}
  • Profile picture of the author colorado1850
    If you're using WordPress, just install and activate one of the SSL plugins. I use Really Simple SSL and it takes care of all the rewrites / redirects for you.

    After you get the htaccess sorted, if it still isn't working, try a site like https://whynopadlock.com

    it will tell you which links are causing the 'mixed content' issue. Hope that helps!
    {{ DiscussionBoard.errors[11349807].message }}
  • Profile picture of the author danoce
    I don't see any problem with your code, you can also check stackoverflow posts about this issue and you will find for sure somebody that has the same problem recently.
    {{ DiscussionBoard.errors[11349914].message }}
  • Profile picture of the author MediaChance
    100% Working Code to Use to Force HTTPS & WWW



    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    #Force www:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
    This Code to Force HTTPS:// without WWW

    Code:
    RewriteCond %{HTTP_HOST} ^(www.)(.+) [OR]
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(www.)?(.+)
    RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
    I Personally use these codes
    Signature

    {{ DiscussionBoard.errors[11371432].message }}
  • Profile picture of the author Voivode
    There's a simple way you can do it from the Cloudflare dashboard. Click on the Crypto icon, then turn on the "Always use HTTPS" setting.


    The "Full SSL (strict)" setting is good to have for security, but it's not relevant to how end users are served content, it only ensures that the connection between Cloudflare and your server is secure.
    {{ DiscussionBoard.errors[11371664].message }}
    • Profile picture of the author MediaChance
      Originally Posted by Voivode View Post

      There's a simple way you can do it from the Cloudflare dashboard. .........

      Really i can say that Cloudflare i'm totally not agree to use cloud-flare, last years i have bad experience, it always show 502 bad gateway , 522 error


      That mean my website gone offlines hours and hours while i spent money to send paid traffic, since i left cloudflare, my websites is become available 24h/7, i started with shared hosting, then VPS, i grow i moved to Semi-dedicated server
      and now i run multi websites through a didicated server.


      I recommend to use SELF Hosted website, as shared info
      Signature

      {{ DiscussionBoard.errors[11371684].message }}
Avatar of Unregistered

Trending Topics