{"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 Place the following code above other rules in your .htaccess file. Just in case it already exists, the 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":"\nhttp:\/\/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
<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