How to redirect or force websites from HTTP to HTTPS via .htaccess. This guide is your blueprint to redirecting your website from the normal HTTP header to the more secured HTTPS. It must be noted that for HTTPS to work on your website, you must purchase and install an SSL certificate on your server. SSL requires paid subscription to leading security
certificate providers such as Comodo and Symantec. One good free alternative is to acquire a free SSL certificate from Lets Encrypt. However, this entails that you have at least SSH access or that your hosting provider allows installation of SSL via the CPanel. Finally, this guide requires intermediate know-how on the intricacies of the .htaccess files.
How to redirect or force websites from HTTP to HTTPS via .htaccess
➤ How to redirect or force websites from HTTP to HTTPS via .htaccess and phpMyAdmin
To begin, use Notepad or your favorite Text Editor (Notepad++, Vim or Brackets), then paste the code below into your .htaccess file. Remember to create a backup before proceeding.
Try the following:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Also, you can redirect based on port number, for example:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Note: You can opt to replace https://%{SERVER_NAME}%{REQUEST_URI} with your sample domain name e.g. https://www.sample.com/$1, as long as you include this line RewriteCond %{HTTP_HOST} ^sample\.com [NC] below the code RewriteEngine On. Also, you can retain ^.* in the rewrite code or use ^(.*) instead. Using these instead of the rewrite code above, will give us this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sample\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.sample.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^sample\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.sample.com/$1 [R,L]
For SEO purposes, you may use [R=301, L] instead of [R,L]. The latter code, [R,L], tells search engines that the authority of the content must remain on the originating domain (http://sample.com for example). This is known as a temporary or a 302 redirect. If you wish to move the SEO content authority to the new domain which for this purpose is https://www.sample.com, then use [R=301,L]. This is better known as a permanent or a 301 Redirect. To implement a 301, look at the code below:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sample\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^.*$ https://www.sample.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^sample\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^.*$ https://www.sample.com/$1 [R=301,L]
You may also apply the rewrite code only to a specific folder:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} subfolder
RewriteRule ^(.*)$ https://www.sample.com/subfolder/$1 [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} subfolder
RewriteRule ^(.*)$ https://www.sample.com/subfolder/$1 [R,L]
Change ‘subfolder’ to your custom folder or directory name.
Let me know if this .htaccess stuff works for you. Remember to create a backup. Please post your comments or suggestions below.
posted May 9, 2018 by THE11thROCK for TeraBlitz.com
FAIR USE DISCLAIMER: The following data is for educational, scholarship review and archiving purposes only. By viewing this information, you release the website and its authors from any responsibility or liabilities. Though we verify and maintain the accuracy of the provided data, the absence of unintented typographical and factual errors cannot be guaranteed. Use the page at your own risk. For any suggestions, updates, credits or correction requests, Contact Us: terablitz.rock@gmail.com
TeraBlitz Steam Header Custom Grid Gloss Pack Download
Related Posts
- How to batch rename files with Windows PowerShell command script
- How to redirect or force websites from HTTP to HTTPS via .htaccess
- How to bulk delete WordPress posts in a category via SQL
- How to change the WordPress Administrator User ID
- How to Clean a Dirty PC DIY
- How To Speed-Up Libre Office Startup and Disable the Splash Screen
Hot Topics
- ProjectAlpha Mod unleashes the new KLA army for Red Alert 2!
- PROJECTALPHA – Legendary RA2 Mod Returns with a New Twist
- Speed Notes released: the ultimate note-taking app for desktop
- TeraBlitz Matrix Green: Unveiling the ultimate Rainmeter skin
- TeraBlitz Geeks releases Holy Bible Desktop Lite for Windows
- Patch 1.1 released for The Walking Horde A20.6 mod
- The Walking Horde Overhaul Mod released for PC
- Blitz Republic Mod now available for download via Steam Workshop
- Blitz Republic Rise of Nations Mod ready for August 2021 release
- Top Notepad alternatives in Windows 10 for 2021
- Best Social Media alternative App downloads 2021
- How to post to Instagram via Desktop Browser
- Quick Fix: Night of the Dead black screens, lags and crashes
- Quick Fix: Fixing Red Alert 2 alt+tab issue in Windows 10
- ABZU Rogue Company Rocket League and Rising Storm 2 Vietnam now free!
- How to batch rename files with Windows PowerShell command script
- How to redirect or force websites from HTTP to HTTPS via .htaccess
- How to bulk delete WordPress posts in a category via SQL
- Ultimate PUBG survival manual with tips, tricks and secrets
- How to change the WordPress Administrator User ID
- Quick Fix: Remove or Hide CS GO Steam Player Profile Picture or Avatar
- Google Hangouts Chat Easter Eggs Cheat Sheet 2018
- Freeware Review: QTTabBar
- Tech News: World of Warcraft Battle for Azeroth Expansion
- Tech News: StarCraft 2 goes Free
- Cossacks 3 PC Cheats Codes Secrets
- Act of War Direct Action PC Cheats Codes Secrets
- TeraBlitz Com plays CSGO De_Dust2 April 3, 2016 A
- Blender 3D Commands – Keyboard Shortcuts Cheat Sheet
- Adam’s Venture Origins PC Cheats, Codes and Secrets
- Games Release News: Adam’s Venture: Origins
- Samsung S7 Tech Sheet
- Hebrew Alphabet and Characters Cheat Sheet
- TeraBlitz Com plays CSGO De_Dust2 April 3, 2016 B
- Japanese Hiragana Alphabet and Characters Cheat Sheet
- Ultimate HTML Entities and Character Reference Cheat Sheet
- Japanese Katakana Alphabet and Characters Cheat Sheet
- CAT5 – CAT6 Color Scheme Wire Combination Cheat Sheet
- Ubuntu Linux Versions Release Cheat Sheet
- Tech News: Ubuntu Linux releases 16.04 LTS Beta 2
- Apple iPhone SE Tech Sheet
- Freeware Review: Panda USB Vaccine
- Games Release: Total War Battles: KINGDOM
- Games Release: StarCraft 2 Nova Covert Ops Mission Pack 1
- Tech News: Heroes of the Storm to add Lost Cavern map
- Games Release: Dawn of Steel for Windows devices
- Quick Fix: Remove or Hide CS GO Hud for Screenshots
- Quick Fix: CS GO Missing Crosshair
- Warcraft 3 PC Cheats, Codes and Secrets
- Tech News: Blizzard’s Warcraft 3 patch 1.27a release notes