{"id":294,"date":"2020-03-15T11:42:20","date_gmt":"2020-03-15T09:42:20","guid":{"rendered":"https:\/\/binaryvikings.io\/?p=294"},"modified":"2020-03-15T11:42:21","modified_gmt":"2020-03-15T09:42:21","slug":"http-redirect-to-https-from-htaccess","status":"publish","type":"post","link":"https:\/\/binaryvikings.io\/?p=294","title":{"rendered":"HTTP redirect to HTTPS from .htaccess"},"content":{"rendered":"\n<p>Here&#8217;s another quick guide! This time on how to redirect HTTP traffic to HTTPS from your .htaccess file.<\/p>\n\n\n\n<p>It&#8217;ll cover how to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Redirect <strong>all<\/strong> traffic from HTTP to HTTPS<\/li><li>Redirect <strong>specific<\/strong> domain from HTTP to HTTPS<\/li><li>Redirect <strong>specific folder<\/strong> from HTTP to HTTPS<\/li><li>Redirect <strong>all<\/strong> traffic, except certain file(s), from HTTP to HTTPS<\/li><\/ul>\n\n\n\n<p>Before we dig into the code. Please make sure to create the <strong>.htaccess<\/strong> file, if not yet created. This file should be located at the root of your website, eg. the <strong>public_html<\/strong> folder.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect all traffic from HTTP to HTTPS<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-directives\" data-file=\".htaccess\" data-lang=\"Directives\"><code>RewriteEngine On\nRewriteCond %{SERVER_PORT} 80\nRewriteRule ^(.*)$ https:\/\/www.YOURDOMAINNAME.com\/$1 [R,L]<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect specific domain from HTTP to HTTPS<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-directives\" data-file=\".htaccess\" data-lang=\"Directives\"><code>RewriteEngine On\nRewriteCond %{HTTP_HOST} ^YOURDOMAINNAME\\.com [NC]\nRewriteCond %{SERVER_PORT} 80\nRewriteRule ^(.*)$ https:\/\/www.YOURDOMAINNAME.com\/$1 [R,L]<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect specific folder from HTTP to HTTPS<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-directives\" data-file=\".htaccess\" data-lang=\"Directives\"><code>RewriteEngine On\nRewriteCond %{SERVER_PORT} 80\nRewriteCond %{REQUEST_URI} foldername\nRewriteRule ^(.*)$ https:\/\/www.YOURDOMAINNAME.com\/foldername\/$1 [R,L]<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect all traffic, except certain file(s), from HTTP to HTTPS<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-directives\" data-file=\".htaccess\" data-lang=\"Directives\"><code>RewriteEngine On\nRewriteCond %{SERVER_PORT} 80 \nRewriteCond %{REQUEST_URI} !^\/FOLDERNAME\/file.xml$ [NC]\nRewriteRule ^(.*)$ https:\/\/www.YOURDOMAINNAME.com\/$1 [R=301,L]<\/code><\/pre><\/div>\n\n\n\n<p>You may specify several files, to not have them redirected to HTTPS.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Over&#8217;n&#8217;Out!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s another quick guide! This time on how to redirect HTTP traffic to HTTPS from your .htaccess file. It&#8217;ll cover how to: Redirect all traffic<\/p>\n","protected":false},"author":1,"featured_media":258,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[12,2,23],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guides","category-security","category-website"],"_links":{"self":[{"href":"https:\/\/binaryvikings.io\/index.php?rest_route=\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/binaryvikings.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/binaryvikings.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/binaryvikings.io\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/binaryvikings.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=294"}],"version-history":[{"count":6,"href":"https:\/\/binaryvikings.io\/index.php?rest_route=\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":300,"href":"https:\/\/binaryvikings.io\/index.php?rest_route=\/wp\/v2\/posts\/294\/revisions\/300"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/binaryvikings.io\/index.php?rest_route=\/wp\/v2\/media\/258"}],"wp:attachment":[{"href":"https:\/\/binaryvikings.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/binaryvikings.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/binaryvikings.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}