{"id":2062,"date":"2021-06-10T15:39:42","date_gmt":"2021-06-10T12:39:42","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=2062"},"modified":"2022-02-03T17:25:18","modified_gmt":"2022-02-03T15:25:18","slug":"how-to-force-ssl-with-htaccess","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/how-to-force-ssl-with-htaccess\/","title":{"rendered":"How to Force SSL with .htaccess"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Even if you have <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/getting-started-with-ssl-certificates\/\"><b>installed an SSL certificate<\/b><\/a><span style=\"font-weight: 400;\">, your website will still be accessible via<\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/http2-support-servers\/\"><span style=\"font-weight: 400;\"> HTTP. <\/span><\/a><span style=\"font-weight: 400;\">To completely secure your website, <\/span><b>use the .htaccess file to force an HTTPS connection.<\/b><span style=\"font-weight: 400;\"> This activity requires the addition of new code to the file.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Forcing Universal HTTPS<\/span><\/h2>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Step 1. <\/b><span style=\"font-weight: 400;\">Log in to your web hosting control panel<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Step 2. <\/b><span style=\"font-weight: 400;\">Find the .htaccess file and open it for editing. You can typically find the file in the root directory of your public_html folder. If the file does not exist, create a blank text file and later save it as .htaccess.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Step 3.<\/b><span style=\"font-weight: 400;\"> Add the following code &#8211;<\/span><\/li>\n<\/ul>\n<p><b><i>RewriteEngine On<\/i><\/b><\/p>\n<p><b><i>RewriteCond %{HTTPS} off<\/i><\/b><\/p>\n<p><b><i>RewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [L,R=301]<\/i><\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Step 4.<\/b><span style=\"font-weight: 400;\"> Save the changes before exiting the file.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">The steps above will enforce HTTPS for all web traffic to the site. You can also specify if you wish to force HTTPS to a specific domain or even a particular folder.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Forcing HTTPS for a Specific Domain<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">If your account handles multiple websites, you may, on occasion, wish to enforce HTTPS for specific sites. If so,<\/span><b> add the following code instead:<\/b><i><\/i><\/p>\n<ul>\n<li><i><span style=\"font-weight: 400;\">RewriteEngine On&nbsp;<\/span><\/i><\/li>\n<li><i><span style=\"font-weight: 400;\">RewriteCond %{HTTP_HOST} ^yourhttpsdomain.com [NC]&nbsp;<\/span><\/i><\/li>\n<li><i><span style=\"font-weight: 400;\">RewriteCond %{HTTPS} off&nbsp;<\/span><\/i><\/li>\n<li><i><span style=\"font-weight: 400;\">RewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [R=301,L]<\/span><\/i><\/li>\n<\/ul>\n<p><b>Replace \u201cyourhttpsdomain.com<\/b><span style=\"font-weight: 400;\">\u201d with the domain name for which you wish to force HTTPS.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Forcing HTTPS on a Specific Folder<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Aside from entire domain names, the .htaccess file can also force HTTPS for specific folder content only. If this is the case, <\/span><b>add the following code<\/b><span style=\"font-weight: 400;\">:<\/span><i><\/i><\/p>\n<ul>\n<li><i><span style=\"font-weight: 400;\">RewriteEngine On&nbsp;<\/span><\/i><\/li>\n<li><i><span style=\"font-weight: 400;\">RewriteCond %{REQUEST_URI} folder<\/span><\/i><\/li>\n<li><i><span style=\"font-weight: 400;\">RewriteRule ^(.*)$ https:\/\/www.yourwebsite.com\/folder\/$1 [R,L]<\/span><\/i><\/li>\n<\/ul>\n<p><b>Replace \u201cfolder\u201d <\/b><span style=\"font-weight: 400;\">with the name of the folder for which you want to force HTTPS. Replace&nbsp; www.yourwebsite.com with the domain name to which the folder belongs.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Even if you have installed an SSL certificate, your website will still be accessible via HTTP. To completely secure your website, use the .htaccess file to force an HTTPS connection. This activity requires the addition of new code to the file. Forcing Universal HTTPS Step 1. Log in to your web hosting control panel Step [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-2062","post","type-post","status-publish","format-standard","hentry","category-web-hosting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=2062"}],"version-history":[{"count":4,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2062\/revisions"}],"predecessor-version":[{"id":3102,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2062\/revisions\/3102"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=2062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=2062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=2062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}