{"id":50174,"date":"2021-07-13T15:40:37","date_gmt":"2021-07-13T15:40:37","guid":{"rendered":"https:\/\/www.awardspace.com\/?p=50174"},"modified":"2024-02-28T13:36:43","modified_gmt":"2024-02-28T13:36:43","slug":"force-https-with-htaccess","status":"publish","type":"post","link":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/","title":{"rendered":"How to force HTTPS with .htaccess"},"content":{"rendered":"<p>Security has become an important part of every website. Almost every website which you visit now has an SSL Certificate installed. We also have a detailed guide that can help you to <a href=\"\/kb\/ssl-certificate-installation\/\" target=\"_blank\" rel=\"noreferrer noopener\">install an SSL Certificate<\/a>. However, installing an SSL Certificate alone on your website would not secure it. To make sure that your SSL Certificate is active you would have to force an HTTPS connection for your website. In this article, we will show you how to force HTTPS on your website using a .htaccess file.<\/p>\n<p>&nbsp;<\/p>\n<h2>Forwarding all Traffic to HTTPS<\/h2>\n<p>While most CMS, used to create a website, have the option to force HTTPS for your website with just one click. However, other websites require some additional configurations to the website to redirect the traffic to HTTPS. This is achieved using .htaccess and one of its many functions, the 301 redirects. To force all of the incoming to your website traffic to use HTTPS follow the steps below:<\/p>\n<ol>\n<li>Go to the File Manager in your Hosting Control Panel<\/li>\n<li>Create a .htaccess file if it does not exist<\/li>\n<li>Open the .htaccess file and add the following code:<br \/>\nRewriteEngine On<br \/>\nRewriteCond %{HTTPS} off<br \/>\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [L,R=301]<\/li>\n<li>Save the changes<\/li>\n<\/ol>\n<p>Make sure that RewriteEngine On is not repeated twice. In case it exists, simply copy the rest of the code without it.<\/p>\n<p>&nbsp;<\/p>\n<h2>Forwarding to HTTPS for a Specific Domain<\/h2>\n<p>Forcing HTTPS for a specific domain would be used in cases where you have multiple domains that point to the same website. However, you want to force HTTPS only for one of the domains. If you would like to achieve that simply use the code below:<\/p>\n<p>RewriteEngine On<br \/>\nRewriteCond %{HTTP_HOST} ^yourdomain.com [NC]<br \/>\nRewriteCond %{HTTPS} off<br \/>\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [R=301,L]<\/p>\n<p>Make sure to replace yourdomain.com with the domain name for which you would like to force HTTPS.<\/p>\n<p>&nbsp;<\/p>\n<h2>Forwarding to HTTPS for a Specific Directory<\/h2>\n<p>Using .htaccess you can also force HTTPS for specific directories. However, the .htaccess file needs to be placed in the directory in which you would like to have the redirection enabled:<\/p>\n<p>RewriteEngine On<br \/>\nRewriteCond %{HTTPS} off<br \/>\nRewriteRule ^(folder1|folder2|folder3) https:\/\/%{HTTP_HOST}%{REQUEST_URI} [R=301,L]<\/p>\n<p>In the above code, you should replace the <strong>folder <\/strong>with the name of the actual directory.<\/p>\n<p>We also have a <a href=\"\/kb\/how-to-use-the-htaccess-generator\/\" target=\"_blank\" rel=\"noreferrer noopener\">.htaccess Generator<\/a> which you can use to generate a .htaccess file for blocking and forwarding traffic or for setting up custom error pages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Security has become an important part of every website. Almost every website which you visit now has an SSL Certificate installed. We also have a detailed guide that can help you to install an SSL Certificate. However, installing an SSL Certificate alone on your website would not secure it. To make sure that your SSL [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":33819,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[78],"tags":[],"class_list":["post-50174","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-htaccess"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to force HTTPS with .htaccess | AwardSpace | Knowledge Base<\/title>\n<meta name=\"description\" content=\"In this article we will show you how to force HTTPS on your website using a .htaccess file with just few lines of code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.awardspace.com\/kb\/force-https-with-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 with .htaccess | AwardSpace | Knowledge Base\" \/>\n<meta property=\"og:description\" content=\"In this article we will show you how to force HTTPS on your website using a .htaccess file with just few lines of code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/\" \/>\n<meta property=\"og:site_name\" content=\"AwardSpace.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AwardSpace\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-13T15:40:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-28T13:36:43+00:00\" \/>\n<meta name=\"author\" content=\"Svetlozar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@awspace\" \/>\n<meta name=\"twitter:site\" content=\"@awspace\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Svetlozar\" \/>\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\":\"Article\",\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/\"},\"author\":{\"name\":\"Svetlozar\",\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/person\/d6b88a5bc5b68653dc64ebcb783f0767\"},\"headline\":\"How to force HTTPS with .htaccess\",\"datePublished\":\"2021-07-13T15:40:37+00:00\",\"dateModified\":\"2024-02-28T13:36:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/\"},\"wordCount\":421,\"publisher\":{\"@id\":\"https:\/\/www.awardspace.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#primaryimage\"},\"thumbnailUrl\":\"\",\"articleSection\":[\".htaccess\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/\",\"url\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/\",\"name\":\"How to force HTTPS with .htaccess | AwardSpace | Knowledge Base\",\"isPartOf\":{\"@id\":\"https:\/\/www.awardspace.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#primaryimage\"},\"thumbnailUrl\":\"\",\"datePublished\":\"2021-07-13T15:40:37+00:00\",\"dateModified\":\"2024-02-28T13:36:43+00:00\",\"description\":\"In this article we will show you how to force HTTPS on your website using a .htaccess file with just few lines of code.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.awardspace.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Knowledge Base\",\"item\":\"https:\/\/www.awardspace.com\/kb\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Website Management \u2013 Advanced\",\"item\":\"https:\/\/www.awardspace.com\/kb\/website-management-advanced\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\".htaccess\",\"item\":\"https:\/\/www.awardspace.com\/kb\/website-management-advanced\/htaccess\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to force HTTPS with .htaccess\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.awardspace.com\/#website\",\"url\":\"https:\/\/www.awardspace.com\/\",\"name\":\"AwardSpace.com\",\"description\":\"Free Web Hosting with PHP, MySQL, Email Sending, No Ads\",\"publisher\":{\"@id\":\"https:\/\/www.awardspace.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.awardspace.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.awardspace.com\/#organization\",\"name\":\"AwardSpace.com\",\"url\":\"https:\/\/www.awardspace.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.awardspace.com\/wp-content\/uploads\/2018\/08\/awardspace_logo.png\",\"contentUrl\":\"https:\/\/www.awardspace.com\/wp-content\/uploads\/2018\/08\/awardspace_logo.png\",\"width\":1759,\"height\":176,\"caption\":\"AwardSpace.com\"},\"image\":{\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/AwardSpace\/\",\"https:\/\/x.com\/awspace\",\"https:\/\/www.instagram.com\/awardspace\/\",\"https:\/\/www.quora.com\/profile\/Award-Space\",\"https:\/\/www.linkedin.com\/company\/19214384\/\",\"https:\/\/www.reddit.com\/user\/AwardSpace\",\"https:\/\/www.pinterest.com\/awardspace\/\",\"https:\/\/www.youtube.com\/user\/AwardspaceWebHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/person\/d6b88a5bc5b68653dc64ebcb783f0767\",\"name\":\"Svetlozar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4e418ad46c73944bc649ba95ca690a2bb80245f4dd05b3c668493877fae295ab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4e418ad46c73944bc649ba95ca690a2bb80245f4dd05b3c668493877fae295ab?s=96&d=mm&r=g\",\"caption\":\"Svetlozar\"},\"url\":\"https:\/\/www.awardspace.com\/author\/svetlozar\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to force HTTPS with .htaccess | AwardSpace | Knowledge Base","description":"In this article we will show you how to force HTTPS on your website using a .htaccess file with just few lines of code.","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:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/","og_locale":"en_US","og_type":"article","og_title":"How to force HTTPS with .htaccess | AwardSpace | Knowledge Base","og_description":"In this article we will show you how to force HTTPS on your website using a .htaccess file with just few lines of code.","og_url":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/","og_site_name":"AwardSpace.com","article_publisher":"https:\/\/www.facebook.com\/AwardSpace\/","article_published_time":"2021-07-13T15:40:37+00:00","article_modified_time":"2024-02-28T13:36:43+00:00","author":"Svetlozar","twitter_card":"summary_large_image","twitter_creator":"@awspace","twitter_site":"@awspace","twitter_misc":{"Written by":"Svetlozar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#article","isPartOf":{"@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/"},"author":{"name":"Svetlozar","@id":"https:\/\/www.awardspace.com\/#\/schema\/person\/d6b88a5bc5b68653dc64ebcb783f0767"},"headline":"How to force HTTPS with .htaccess","datePublished":"2021-07-13T15:40:37+00:00","dateModified":"2024-02-28T13:36:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/"},"wordCount":421,"publisher":{"@id":"https:\/\/www.awardspace.com\/#organization"},"image":{"@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#primaryimage"},"thumbnailUrl":"","articleSection":[".htaccess"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/","url":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/","name":"How to force HTTPS with .htaccess | AwardSpace | Knowledge Base","isPartOf":{"@id":"https:\/\/www.awardspace.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#primaryimage"},"image":{"@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#primaryimage"},"thumbnailUrl":"","datePublished":"2021-07-13T15:40:37+00:00","dateModified":"2024-02-28T13:36:43+00:00","description":"In this article we will show you how to force HTTPS on your website using a .htaccess file with just few lines of code.","breadcrumb":{"@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/www.awardspace.com\/kb\/force-https-with-htaccess\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.awardspace.com\/"},{"@type":"ListItem","position":2,"name":"Knowledge Base","item":"https:\/\/www.awardspace.com\/kb\/"},{"@type":"ListItem","position":3,"name":"Website Management \u2013 Advanced","item":"https:\/\/www.awardspace.com\/kb\/website-management-advanced\/"},{"@type":"ListItem","position":4,"name":".htaccess","item":"https:\/\/www.awardspace.com\/kb\/website-management-advanced\/htaccess\/"},{"@type":"ListItem","position":5,"name":"How to force HTTPS with .htaccess"}]},{"@type":"WebSite","@id":"https:\/\/www.awardspace.com\/#website","url":"https:\/\/www.awardspace.com\/","name":"AwardSpace.com","description":"Free Web Hosting with PHP, MySQL, Email Sending, No Ads","publisher":{"@id":"https:\/\/www.awardspace.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.awardspace.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.awardspace.com\/#organization","name":"AwardSpace.com","url":"https:\/\/www.awardspace.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.awardspace.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.awardspace.com\/wp-content\/uploads\/2018\/08\/awardspace_logo.png","contentUrl":"https:\/\/www.awardspace.com\/wp-content\/uploads\/2018\/08\/awardspace_logo.png","width":1759,"height":176,"caption":"AwardSpace.com"},"image":{"@id":"https:\/\/www.awardspace.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/AwardSpace\/","https:\/\/x.com\/awspace","https:\/\/www.instagram.com\/awardspace\/","https:\/\/www.quora.com\/profile\/Award-Space","https:\/\/www.linkedin.com\/company\/19214384\/","https:\/\/www.reddit.com\/user\/AwardSpace","https:\/\/www.pinterest.com\/awardspace\/","https:\/\/www.youtube.com\/user\/AwardspaceWebHosting"]},{"@type":"Person","@id":"https:\/\/www.awardspace.com\/#\/schema\/person\/d6b88a5bc5b68653dc64ebcb783f0767","name":"Svetlozar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.awardspace.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4e418ad46c73944bc649ba95ca690a2bb80245f4dd05b3c668493877fae295ab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4e418ad46c73944bc649ba95ca690a2bb80245f4dd05b3c668493877fae295ab?s=96&d=mm&r=g","caption":"Svetlozar"},"url":"https:\/\/www.awardspace.com\/author\/svetlozar\/"}]}},"_links":{"self":[{"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/posts\/50174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/comments?post=50174"}],"version-history":[{"count":0,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/posts\/50174\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/media?parent=50174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/categories?post=50174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/tags?post=50174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}