Announcement

Collapse
No announcement yet.

Redirecting HTTP to HTTPS Using .htaccess File

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Redirecting HTTP to HTTPS Using .htaccess File

    https.png



    Redirecting HTTP to HTTPS

    1. Redirect All Web Traffic


    If you have existing code in your .htaccess, add the following:

    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
    2. Redirect Only a Specific Domain


    For redirecting a specific domain to use HTTPS, add the following:

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
    3. Redirect Only a Specific Folder


    Redirecting to HTTPS on a specific folder, add the following:
    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{REQUEST_URI} folder
    RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]

    Note: Replace “yourdomain” with your actual domain name wherever required. Also, in case of the folder, replace /folder with the actual folder name.
    Last edited by DaMysterious; 03-18-2019, 01:03 PM.

  • #2
    thanks for sharing, but how can i solve if redirecting specific domains (multiple domains) to https

    Comment


    • #3
      To redirect ONLY specific domains to HTTPS with .htaccess.

      Code:
      RewriteEngine on
      
      # Redirect all domains to use 'www.'
      
      ​RewriteCond %{HTTP_HOST} .
      RewriteCond %{HTTP_HOST} !^www\. [NC]
      RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
      
      # Redirect ONLY specific domains to HTTPS
      
      RewriteCond %{HTTP_HOST} ^(www\.)?(domain1.com|domain2.com|domain3.net)$
      RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
      RewriteCond %{HTTPS} off
      RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
      What the above does is:
      1. Redirects all domains to use 'www.'
      2. Checks if visitor is on www.domain1.com, www.domain2.com, or www.domain3.net
      3. Checks to see if HTTPS is NOT used.
      4. Redirects the above domains to use HTTPS

      And that's that... The above should be pretty much minimum resource intensive, as we're first getting global tasks out the way first (change all domains to use 'www.'), followed by only processing criteria for specific domains and nothing else.

      Rewrite ALL domains to use HTTPS

      Code:
        
      # Redirect to HTTPS
      RewriteCond %{HTTPS} off
      RewriteCond %{HTTP:X-Forwarded-Proto} !https
      RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

      Above mentioned will check to see if HTTPS is being used, IF NOT, then redirects to HTTPS.

      Comment


      • #4
        thanks for helping me out. After the setting i tested my website on https://www.whynopadlock.com and got all green result. Now SSL implemented fully.

        Comment

        Working...
        X