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
    SEMrush
     
    Solved! View solution.
    jaguar34, Jun 15, 2020 IP
    SEMrush
  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:
    523
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    150
    #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:
    6,604
    Likes Received:
    1,433
    Best Answers:
    25
    Trophy Points:
    425
    #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,763
    Likes Received:
    1,195
    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.