1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Redirect to https:// from non-SSL

Discussion in 'Site & Server Administration' started by jaguar34, Jun 15, 2020.

  1. #1
    What should be the code in .htaccess for redirecting to https version of website from Non-SSL? The website is html based
     
    Solved! View solution.
    jaguar34, Jun 15, 2020 IP
  2. #2
    
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
    
    Code (markup):
     
    qwikad.com, Jun 15, 2020 IP
    dcristo, sarahk and jaguar34 like this.
  3. seomanualsubmission

    seomanualsubmission Well-Known Member

    Messages:
    905
    Likes Received:
    128
    Best Answers:
    4
    Trophy Points:
    165
    #3
    Yes this is perfect ..... You can add some more like ensure that site is opening with www or without www ...... permanently redirect from http to https etc. Take a look at below code with some additional parameters.

    Options +FollowSymLinks
    RewriteEngine on
    # ensure www. (If prefer without www then remove this section)
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # ensure https
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    Code (markup):
     
    seomanualsubmission, Jun 15, 2020 IP
  4. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #4
    The greedy regex (.*) does that. It matches the URL with or without www. and/or http://

     
    qwikad.com, Jun 16, 2020 IP
  5. dcristo

    dcristo Illustrious Member

    Messages:
    19,776
    Likes Received:
    1,199
    Best Answers:
    7
    Trophy Points:
    470
    Articles:
    7
    #5
    Thanks, this worked well. But for SEO purposes you want to setup a 301 redirect.

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    Code (markup):
     
    dcristo, Nov 23, 2020 IP
    qwikad.com likes this.