{"id":433,"date":"2021-09-11T11:51:59","date_gmt":"2021-09-11T06:06:59","guid":{"rendered":"https:\/\/yoho.cloud\/blog\/?p=433"},"modified":"2021-09-17T21:25:11","modified_gmt":"2021-09-17T15:40:11","slug":"redirect-http-to-https-using-htaccess","status":"publish","type":"post","link":"https:\/\/yoho.cloud\/blog\/redirect-http-to-https-using-htaccess\/","title":{"rendered":"Redirect HTTP to HTTPS using .htaccess"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/yoho.cloud\/blog\/redirect-http-to-https-using-htaccess\/#How_to_Redirect_HTTP_to_HTTPS_using_htaccess\" >How to Redirect HTTP to HTTPS using .htaccess?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/yoho.cloud\/blog\/redirect-http-to-https-using-htaccess\/#Forcing_HTTPS_on_a_Specific_Domain\" >Forcing HTTPS on a Specific Domain<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/yoho.cloud\/blog\/redirect-http-to-https-using-htaccess\/#Forcing_HTTPS_on_a_Specific_Folder\" >Forcing HTTPS on a Specific Folder<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<p><span style=\"font-weight: 400;\">With .htaccess, you can perform 301 redirects, i.e., permanently redirecting an old URL to a new one. <\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Redirect_HTTP_to_HTTPS_using_htaccess\"><\/span><span style=\"font-weight: 400;\">How to Redirect HTTP to HTTPS using .htaccess?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\"> Follow these steps to force HTTPS on all incoming traffic:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Step 1: Log in to cPanel, and Under the <\/span><b>FILES <\/b><span style=\"font-weight: 400;\">section, click on <\/span><b>File Manager<\/b><span style=\"font-weight: 400;\">.<\/span><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-434\" src=\"https:\/\/yoho.cloud\/blog\/wp-content\/uploads\/2021\/09\/redirection-ssl.png\" alt=\"\" width=\"512\" height=\"86\" srcset=\"https:\/\/yoho.cloud\/blog\/wp-content\/uploads\/2021\/09\/redirection-ssl.png 512w, https:\/\/yoho.cloud\/blog\/wp-content\/uploads\/2021\/09\/redirection-ssl-150x25.png 150w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/p>\n<p>Step 2: A <strong>File manager<\/strong> window appears where you can see the <strong>public_html<\/strong> folder. You can navigate from either side, left or right.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-435\" src=\"https:\/\/yoho.cloud\/blog\/wp-content\/uploads\/2021\/09\/redirection-ssl-step.png\" alt=\"\" width=\"512\" height=\"376\" srcset=\"https:\/\/yoho.cloud\/blog\/wp-content\/uploads\/2021\/09\/redirection-ssl-step.png 512w, https:\/\/yoho.cloud\/blog\/wp-content\/uploads\/2021\/09\/redirection-ssl-step-150x110.png 150w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Step 3: Browse to <\/span><b>.htaccess<\/b><span style=\"font-weight: 400;\"> inside the public_html folder. Be sure to create or unhide it if you can&#8217;t find it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0Step 4: Search <\/span><b>RewriteEngine On <\/b><span style=\"font-weight: 400;\">text in the file<\/span> <span style=\"font-weight: 400;\">and then insert the below codes.<\/span><\/p>\n<div class=\"preboxcontainer\">\n<pre class=\"prebox\"><i><span style=\"font-weight: 400;\">RewriteCond %{HTTPS} off\u00a0<\/span><\/i>\r\n\r\n<i><span style=\"font-weight: 400;\">RewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [L,R=301]<\/span><\/i>\r\n<span style=\"font-weight: 400;\">Step 5: Click <\/span><b>Save <\/b><span style=\"font-weight: 400;\">the changes.<\/span><\/pre>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"Forcing_HTTPS_on_a_Specific_Domain\"><\/span><b>Forcing HTTPS on a Specific Domain<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">You can do that when you have multiple websites but want to get traffic in only one domain. For example, You have two domains: http:\/\/firstdomain.com and http:\/\/seconddomain.com accessing the same website. And you just wish for the first domain to be redirected to the HTTPS version.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Using the following codes to <\/span><b>force HTTPS on a specific domain:<\/b><\/p>\n<div class=\"preboxcontainer\">\n<pre class=\"prebox\"><i><span style=\"font-weight: 400;\">RewriteEngine On\u00a0<\/span><\/i>\r\n\r\n<i><span style=\"font-weight: 400;\">RewriteCond %{HTTP_HOST} ^<\/span><\/i><b><i>firstdomain.com<\/i><\/b><i><span style=\"font-weight: 400;\"> [NC]\u00a0<\/span><\/i>\r\n\r\n<i><span style=\"font-weight: 400;\">RewriteCond %{HTTPS} off\u00a0<\/span><\/i>\r\n\r\n<i><span style=\"font-weight: 400;\">RewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [R=301,L]<\/span><\/i>\r\n<\/pre>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"Forcing_HTTPS_on_a_Specific_Folder\"><\/span><b>Forcing HTTPS on a Specific Folder<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">You can also use the .htaccess file to force HTTPS on particular folders. Place the file, however, in the folder that will have the HTTPS connection.<\/span><\/p>\n<div class=\"preboxcontainer\">\n<pre class=\"prebox\"><i><span style=\"font-weight: 400;\">RewriteEngine On\u00a0<\/span><\/i>\r\n\r\n<i><span style=\"font-weight: 400;\">RewriteCond %{HTTPS} off\u00a0<\/span><\/i>\r\n\r\n<i><span style=\"font-weight: 400;\">RewriteRule ^(folder1|folder2|folder3) https:\/\/%{HTTP_HOST}%{REQUEST_URI} [R=301,L] <\/span><\/i>\r\n\r\n<\/pre>\n<\/div>\n<p><b>Note: <\/b><span style=\"font-weight: 400;\">Do replace the folder name with the one you want to.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Clear the cache of your browser and try it again. You can now try to connect to your site via HTTP. Once all the required fields are filled, the browser will redirect you to the HTTPS version.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Therefore, from the above three ways, you can force traffic to your HTTPS Version.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With .htaccess, you can perform 301 redirects, i.e., permanently redirecting an old URL to a new one. How to Redirect HTTP to HTTPS using .htaccess? Follow these steps to force HTTPS on all incoming traffic: Step 1: Log in to cPanel, and Under the FILES section, click on File Manager. Step 2: A File manager [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":436,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,24],"tags":[],"class_list":["post-433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel","category-knowledge-base"],"_links":{"self":[{"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":6,"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":485,"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions\/485"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/media\/436"}],"wp:attachment":[{"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yoho.cloud\/blog\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}