Skip to content

Instantly share code, notes, and snippets.

@samazgor
Created August 13, 2020 14:33
Show Gist options
  • Save samazgor/77d683a00b6cb978ff76df7c0ae8ac0e to your computer and use it in GitHub Desktop.
Save samazgor/77d683a00b6cb978ff76df7c0ae8ac0e to your computer and use it in GitHub Desktop.
redirect HTTP to HTTPS Using .htaccess

Redirecting HTTP to HTTPS

  1. Redirect All Web Traffic If you have existing code in your .htaccess, add the following:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
  1. Redirect Only a Specific Domain For redirecting a specific domain to use HTTPS, add the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
  1. Redirect Only a Specific Folder Redirecting to HTTPS on a specific folder, add the following:
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment