{"id":2469,"date":"2022-01-25T10:44:11","date_gmt":"2022-01-25T10:44:11","guid":{"rendered":"https:\/\/intechcloudhosting.com\/blog\/?p=2469"},"modified":"2024-01-18T00:23:52","modified_gmt":"2024-01-18T00:23:52","slug":"how-to-force-https-using-htaccess","status":"publish","type":"post","link":"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/","title":{"rendered":"How to Force HTTPS using .htaccess (Updated 2024)"},"content":{"rendered":"\n<p>An SSL certificate enables your website to be accessible via HTTP and HTTPS protocols. However, you should only use the latter as the latter encrypts and protects your website&#8217;s data. You can also force HTTPS connection with the .htaccess file if your hosting provider doesn&#8217;t allow you to do so in one click.&nbsp;This article will show you how.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-forcing-https-on-all-traffic\"><span id=\"forcing-https-on-all-traffic\">Forcing HTTPS on All Traffic<\/span><\/h2>\n\n\n\n<p>With .htaccess, you can perform many functions including 301 redirects, which replace an old URL with a new one. You can enable HTTPS to be forced on all incoming traffic by following these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Navigate to the <strong>File Manager<\/strong> in your hosting panel and open the <strong>.htaccess<\/strong> file in the <strong>public_html<\/strong> folder. If you can&#8217;t find it, make sure to create it or unhide it.<\/li>\n\n\n\n<li>Scroll down to find <strong>RewriteEngine On<\/strong>, and type the following code underneath it:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On \nRewriteCond %{HTTPS} off \nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;L,R=301]<\/code><\/pre>\n\n\n\n<p>3.<strong> Save your changes.<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>IMPORTANT<\/p>\n<cite>Make sure that the line&nbsp;<strong>RewriteEngine On<\/strong>&nbsp;is not repeated twice. In case the line already exists, simply copy the rest of the code without it.<\/cite><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-forcing-https-on-a-specific-domain\"><span id=\"forcing-https-on-a-specific-domain\">Forcing HTTPS on a Specific Domain<\/span><\/h2>\n\n\n\n<p>Let\u2019s say that you have two domains:&nbsp;<strong>http:\/\/yourdomain1.com&nbsp;<\/strong>and&nbsp;<strong>http:\/\/yourdomain2.com.&nbsp;<\/strong>Both domains access the same website, but you only want the first one to be redirected to the HTTPS version. In this case, you need to use the following code:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On \nRewriteCond %{HTTP_HOST} ^yourdomain1.com &#91;NC] \nRewriteCond %{HTTPS} off \nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;R=301,L]<\/code><\/pre>\n\n\n\n<p>Make sure to replace&nbsp;<strong>yourdomain1&nbsp;<\/strong>with the actual domain you\u2019re trying to force HTTPS on.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-forcing-https-on-a-specific-folder\"><span id=\"forcing-https-on-a-specific-folder\">Forcing HTTPS on a Specific Folder<\/span><\/h2>\n\n\n\n<p>The&nbsp;<strong>.htaccess&nbsp;<\/strong>file can also be used to force HTTPS on specific folders. However, the file should be placed in the folder that will have the HTTPS connection.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On \nRewriteCond %{HTTPS} off \nRewriteRule ^(folder1|folder2|folder3) https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;R=301,L]<\/code><\/pre>\n\n\n\n<p>Make sure to change the&nbsp;<strong>folder<\/strong>&nbsp;references to the actual directory names.<\/p>\n\n\n\n<p>After making the changes, clear your browser\u2019s cache and try to connect to your site via HTTP. If everything was added correctly, the browser will redirect you to the HTTPS version.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span id=\"conclusion\">Conclusion<\/span><\/h2>\n\n\n\n<p>Congratulations! you have successfully edited your&nbsp;<strong>.htaccess file<\/strong>&nbsp;and redirected all HTTP traffic to HTTPS, the safe version of your website. Depending on the platform where you developed your website, there could be alternative methods to enable this feature. For example, you can configure your WordPress or PrestaShop site to work with HTTPS using plugins.<\/p>\n\n\n\n<p>If you have any tips, tricks, or suggestions that you want to share, we are looking forward to seeing them in the comments!<\/p>\n","protected":false},"excerpt":{"rendered":"An SSL certificate enables your website to be accessible via HTTP and HTTPS protocols. However, you should only&hellip;\n","protected":false},"author":1,"featured_media":2471,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,57],"tags":[53,44,45],"class_list":{"0":"post-2469","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-glossary","8":"category-website","9":"tag-featured","10":"tag-htaccess","11":"tag-https","12":"cs-entry","13":"cs-video-wrap"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Force HTTPS using .htaccess (Updated 2024) - Intech Cloud Blog<\/title>\n<meta name=\"description\" content=\"With .htaccess, you can perform many functions including 301 redirects, which replace an old URL with a new one.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Force HTTPS using .htaccess (Updated 2024) - Intech Cloud Blog\" \/>\n<meta property=\"og:description\" content=\"With .htaccess, you can perform many functions including 301 redirects, which replace an old URL with a new one.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/\" \/>\n<meta property=\"og:site_name\" content=\"Intech Cloud Blog\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/intechcloudhosting\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-25T10:44:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-18T00:23:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/intechcloudhosting.com\/blog\/wp-content\/uploads\/2022\/01\/CLOUD-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"4650\" \/>\n\t<meta property=\"og:image:height\" content=\"2725\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Editorial\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editorial\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/\",\"url\":\"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/\",\"name\":\"How to Force HTTPS using .htaccess (Updated 2024) - Intech Cloud Blog\",\"isPartOf\":{\"@id\":\"https:\/\/intechcloudhosting.com\/blog\/#website\"},\"datePublished\":\"2022-01-25T10:44:11+00:00\",\"dateModified\":\"2024-01-18T00:23:52+00:00\",\"author\":{\"@id\":\"https:\/\/intechcloudhosting.com\/blog\/#\/schema\/person\/da8e3a68240778e3388750d01512d070\"},\"description\":\"With .htaccess, you can perform many functions including 301 redirects, which replace an old URL with a new one.\",\"breadcrumb\":{\"@id\":\"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/intechcloudhosting.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Force HTTPS using .htaccess (Updated 2024)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/intechcloudhosting.com\/blog\/#website\",\"url\":\"https:\/\/intechcloudhosting.com\/blog\/\",\"name\":\"Intech Cloud Blog\",\"description\":\"Intech Cloud Hosting Blog and Tutorials Base Section\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/intechcloudhosting.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/intechcloudhosting.com\/blog\/#\/schema\/person\/da8e3a68240778e3388750d01512d070\",\"name\":\"Editorial\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/intechcloudhosting.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c3f6abfaab39056a0c765f80793c60eed0ef6e4beb20483af5d2a4fcc19c7b6b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c3f6abfaab39056a0c765f80793c60eed0ef6e4beb20483af5d2a4fcc19c7b6b?s=96&d=mm&r=g\",\"caption\":\"Editorial\"},\"description\":\"Articles written by Intech Staff.\",\"sameAs\":[\"https:\/\/intechcloudhosting.com\/blog\",\"https:\/\/facebook.com\/intechcloudhosting\",\"https:\/\/instagram.com\/intechcloudhosting\",\"https:\/\/linkedin.com\/showcase\/intechcloudhosting\"],\"url\":\"https:\/\/intechcloudhosting.com\/blog\/author\/editorial\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Force HTTPS using .htaccess (Updated 2024) - Intech Cloud Blog","description":"With .htaccess, you can perform many functions including 301 redirects, which replace an old URL with a new one.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/","og_locale":"en_US","og_type":"article","og_title":"How to Force HTTPS using .htaccess (Updated 2024) - Intech Cloud Blog","og_description":"With .htaccess, you can perform many functions including 301 redirects, which replace an old URL with a new one.","og_url":"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/","og_site_name":"Intech Cloud Blog","article_author":"https:\/\/facebook.com\/intechcloudhosting","article_published_time":"2022-01-25T10:44:11+00:00","article_modified_time":"2024-01-18T00:23:52+00:00","og_image":[{"width":4650,"height":2725,"url":"https:\/\/intechcloudhosting.com\/blog\/wp-content\/uploads\/2022\/01\/CLOUD-1.png","type":"image\/png"}],"author":"Editorial","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editorial","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/","url":"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/","name":"How to Force HTTPS using .htaccess (Updated 2024) - Intech Cloud Blog","isPartOf":{"@id":"https:\/\/intechcloudhosting.com\/blog\/#website"},"datePublished":"2022-01-25T10:44:11+00:00","dateModified":"2024-01-18T00:23:52+00:00","author":{"@id":"https:\/\/intechcloudhosting.com\/blog\/#\/schema\/person\/da8e3a68240778e3388750d01512d070"},"description":"With .htaccess, you can perform many functions including 301 redirects, which replace an old URL with a new one.","breadcrumb":{"@id":"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/intechcloudhosting.com\/blog\/how-to-force-https-using-htaccess\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/intechcloudhosting.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Force HTTPS using .htaccess (Updated 2024)"}]},{"@type":"WebSite","@id":"https:\/\/intechcloudhosting.com\/blog\/#website","url":"https:\/\/intechcloudhosting.com\/blog\/","name":"Intech Cloud Blog","description":"Intech Cloud Hosting Blog and Tutorials Base Section","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/intechcloudhosting.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/intechcloudhosting.com\/blog\/#\/schema\/person\/da8e3a68240778e3388750d01512d070","name":"Editorial","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/intechcloudhosting.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c3f6abfaab39056a0c765f80793c60eed0ef6e4beb20483af5d2a4fcc19c7b6b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c3f6abfaab39056a0c765f80793c60eed0ef6e4beb20483af5d2a4fcc19c7b6b?s=96&d=mm&r=g","caption":"Editorial"},"description":"Articles written by Intech Staff.","sameAs":["https:\/\/intechcloudhosting.com\/blog","https:\/\/facebook.com\/intechcloudhosting","https:\/\/instagram.com\/intechcloudhosting","https:\/\/linkedin.com\/showcase\/intechcloudhosting"],"url":"https:\/\/intechcloudhosting.com\/blog\/author\/editorial\/"}]}},"images":{"small":"https:\/\/intechcloudhosting.com\/blog\/wp-content\/uploads\/2022\/01\/CLOUD-1.png","medium":"https:\/\/intechcloudhosting.com\/blog\/wp-content\/uploads\/2022\/01\/CLOUD-1-300x176.png","large":"https:\/\/intechcloudhosting.com\/blog\/wp-content\/uploads\/2022\/01\/CLOUD-1-1024x600.png"},"_links":{"self":[{"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/posts\/2469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=2469"}],"version-history":[{"count":2,"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/posts\/2469\/revisions"}],"predecessor-version":[{"id":3068,"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/posts\/2469\/revisions\/3068"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/media\/2471"}],"wp:attachment":[{"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=2469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=2469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intechcloudhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=2469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}