{"id":8109,"date":"2019-10-30T11:17:09","date_gmt":"2019-10-30T15:17:09","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=8109"},"modified":"2021-12-08T10:49:29","modified_gmt":"2021-12-08T15:49:29","slug":"redirect-http-https","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/redirect-http-https\/","title":{"rendered":"Using .htaccess to Redirect HTTP to HTTPS"},"content":{"rendered":"\n

For obvious, or not so obvious security reasons, it is important to redirect all your web<\/a> traffic from HTTP to HTTPS. There are various ways you can do it. However, in this guide, we shall take a look at how you can do it using Apache’s .htaccess rules.<\/p>\n\n\n\n

.htaccess has got a somewhat strict syntax and therefore it is so easy to get things wrong with the slightest error. The other thing to note is that the various rules that are placed and processed in the file are done so in order from top to bottom.<\/p>\n\n\n\n

With this in mind, it serves as a starting point to understanding where issues like the ‘ERR_TOO_MANY_REDIRECTS<\/strong>‘ originate from. Examples of causes of the aforementioned error include badly formed rules, where rules are affected by other sources such as Cloudflare<\/a> or WordPress plugins that add additional conflicting rules to the same .htaccess file.<\/p>\n\n\n\n

Another good example is found in WordPress where the ‘site_url’ and ‘home’ are defined in the admin dashboard as http:\/\/example.com<\/code> instead of https:\/\/example.com<\/code>. What happens here is WordPress redirects the website to HTTP and the .htaccess redirects the website back to HTTPS causing endless redirects.<\/p>\n\n\n\n

The Redirect HTTP to HTTPS Fix<\/h2>\n\n\n\n

Place the following code above other rules in your .htaccess file. Just in case it already exists, the <IfModule mod_rewrite.c> ... <\/IfModule><\/code> part can be repeated multiple times in your file so it is okay to have it there.<\/p>\n\n\n\n

<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase \/\n\nRewriteCond %{HTTPS} !=on\nRewriteRule ^ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n<\/IfModule><\/code><\/pre>\n\n\n\n

The above snippet will redirect HTTP to HTTPS before doing anything else that the rest of your file rules direct. There you have it.<\/p>\n","protected":false},"excerpt":{"rendered":"

For obvious, or not so obvious security reasons, it is important to redirect all your web traffic from HTTP to HTTPS. There are various ways you can do it. However,…<\/p>\n","protected":false},"author":1,"featured_media":8110,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,16],"tags":[58,304,320,424,433,452,531,543,544,635,636,637,638],"yoast_head":"\nHow to Properly Redirect HTTP to HTTPS Using .htaccess<\/title>\n<meta name=\"description\" content=\"Here is a quick guide showing how to forcefully redirect PHP web pages from HTTP to HTTPS using .htaccess in Apache web server\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/redirect-http-https\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Properly Redirect HTTP to HTTPS Using .htaccess\" \/>\n<meta property=\"og:description\" content=\"Here is a quick guide showing how to forcefully redirect PHP web pages from HTTP to HTTPS using .htaccess in Apache web server\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/redirect-http-https\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-30T15:17:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-08T15:49:29+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\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\":\"http:\/\/local.brightwhiz\/redirect-http-https\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"Using .htaccess to Redirect HTTP to HTTPS\",\"datePublished\":\"2019-10-30T15:17:09+00:00\",\"dateModified\":\"2021-12-08T15:49:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/\"},\"wordCount\":269,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg\",\"keywords\":[\"Apache\",\"HTTP\",\"Internet\",\"Open Source\",\"Optimization\",\"PHP\",\"Server\",\"Software Design\",\"Software development\",\"Web\",\"Web Applications\",\"Web Design\",\"Web Development\"],\"articleSection\":[\"Articles\",\"Guides\",\"How To\",\"Technology\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/\",\"url\":\"http:\/\/local.brightwhiz\/redirect-http-https\/\",\"name\":\"How to Properly Redirect HTTP to HTTPS Using .htaccess\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg\",\"datePublished\":\"2019-10-30T15:17:09+00:00\",\"dateModified\":\"2021-12-08T15:49:29+00:00\",\"description\":\"Here is a quick guide showing how to forcefully redirect PHP web pages from HTTP to HTTPS using .htaccess in Apache web server\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/redirect-http-https\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/#primaryimage\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg\",\"width\":1200,\"height\":630,\"caption\":\"Redirect HTTP to HTTPS\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/redirect-http-https\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using .htaccess to Redirect HTTP to HTTPS\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/twitter.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Properly Redirect HTTP to HTTPS Using .htaccess","description":"Here is a quick guide showing how to forcefully redirect PHP web pages from HTTP to HTTPS using .htaccess in Apache web server","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":"http:\/\/local.brightwhiz\/redirect-http-https\/","og_locale":"en_US","og_type":"article","og_title":"How to Properly Redirect HTTP to HTTPS Using .htaccess","og_description":"Here is a quick guide showing how to forcefully redirect PHP web pages from HTTP to HTTPS using .htaccess in Apache web server","og_url":"http:\/\/local.brightwhiz\/redirect-http-https\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2019-10-30T15:17:09+00:00","article_modified_time":"2021-12-08T15:49:29+00:00","og_image":[{"width":1200,"height":630,"url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg","type":"image\/jpeg"}],"author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/redirect-http-https\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/redirect-http-https\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"Using .htaccess to Redirect HTTP to HTTPS","datePublished":"2019-10-30T15:17:09+00:00","dateModified":"2021-12-08T15:49:29+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/redirect-http-https\/"},"wordCount":269,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"image":{"@id":"http:\/\/local.brightwhiz\/redirect-http-https\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg","keywords":["Apache","HTTP","Internet","Open Source","Optimization","PHP","Server","Software Design","Software development","Web","Web Applications","Web Design","Web Development"],"articleSection":["Articles","Guides","How To","Technology"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/redirect-http-https\/","url":"http:\/\/local.brightwhiz\/redirect-http-https\/","name":"How to Properly Redirect HTTP to HTTPS Using .htaccess","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"primaryImageOfPage":{"@id":"http:\/\/local.brightwhiz\/redirect-http-https\/#primaryimage"},"image":{"@id":"http:\/\/local.brightwhiz\/redirect-http-https\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg","datePublished":"2019-10-30T15:17:09+00:00","dateModified":"2021-12-08T15:49:29+00:00","description":"Here is a quick guide showing how to forcefully redirect PHP web pages from HTTP to HTTPS using .htaccess in Apache web server","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/redirect-http-https\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/redirect-http-https\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/redirect-http-https\/#primaryimage","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/10\/http-to-https.jpg","width":1200,"height":630,"caption":"Redirect HTTP to HTTPS"},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/redirect-http-https\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"Using .htaccess to Redirect HTTP to HTTPS"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/twitter.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/8109"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=8109"}],"version-history":[{"count":0,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/8109\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media\/8110"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=8109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=8109"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=8109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}