{"id":10798,"date":"2020-06-26T06:05:55","date_gmt":"2020-06-26T12:05:55","guid":{"rendered":"https:\/\/sanuja.com\/blog\/?p=10798"},"modified":"2020-07-24T08:20:57","modified_gmt":"2020-07-24T14:20:57","slug":"force-ssl-tls-https-with-htaccess","status":"publish","type":"post","link":"https:\/\/sanuja.com\/blog\/force-ssl-tls-https-with-htaccess","title":{"rendered":"Force SSL\/TLS (HTTPS) with .htaccess"},"content":{"rendered":"<p>Google has announced that implementation of TLS (SSL) certificates benefit the web site owners and can boost SEO ranking of your website. Secure Sockets Layer (SSL) is the predecessor to Transport Layer Security (TLS). It is a misnomer that people call SSL and TLS are interchangeable. Simply put, as a website owner, what you should care about is that your website requests are served in <strong>HTTPS<\/strong> (port 443) rather than <strong>HTTP<\/strong> (port 80) with a valid certificate.<\/p>\n<p><!--more--><\/p>\n<p>This guide is based on the .htaccess file which is a directory-level configuration file supported by several web servers such as Apache web server. You can read more at <a href=\"https:\/\/en.wikipedia.org\/wiki\/.htaccess\" target=\"_blank\" rel=\"noopener noreferrer\">Wikipedia<\/a>.<\/p>\n<p>The first thing you need to make sure that you have installed the certificate authority files on your web server. If you have purchased web hosting from a reputed company, you will most likely have free TLS certificates installed by default or you can choose to go with a paid service. If you host yourself, you can install Let\u2019s Encrypt is a free open source TLS certificates on your server. I will not go into detail on how to install the certificate yourself in this article.<\/p>\n<p>If you have WordPress CMS, please do not modify your .htaccess manually. You can do it with a plugin called <a href=\"https:\/\/wordpress.org\/plugins\/really-simple-ssl\/\" rel=\"noopener noreferrer\" target=\"_blank\">Really Simple SSL<\/a>. Please install the Really Simple SSL plugin and follow their instructions. This can also fix the mixed content error.<\/p>\n<div class=\"alert alert-warning\" role=\"alert\"><p class=\"printonly\"><strong>Warning!<\/strong><\/p>Editing the .htaccess file may result in complete failure of the web server because it override global configuration settings. As a result, incorrect entries may put your website out of service. If you are hesitant about something, hire a professional. I take no responsibility for any issues arise out of the following instructions.<\/div>\n<p>You can force HTTPS connections on your website by adding the following rules to your .htaccess file in the domain root folder. This type of redirection is known as a HTTP 301 redirect.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nRewriteEngine On\r\nRewriteCond %{HTTPS} off\r\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#x5B;R=301,L]\r\n<\/pre>\n<p>The above code will result in directing all request to http:\/\/sanuja.com\/[what ever the page link] to https:\/\/sanuja.com\/[what ever the page link].<\/p>\n<p>You can see that TLS connection is working when your URL has HTTP<strong>S<\/strong> and the certificate is valid (lock symbol on the address bar on most browsers).<\/p>\n<h2>How do I fix mixed content error?<\/h2>\n<p>Mixed content occurs when initial HTML is loaded over a secure HTTPS connection, but <a href=\"https:\/\/developers.google.com\/web\/fundamentals\/security\/prevent-mixed-content\/what-is-mixed-content\" rel=\"noopener noreferrer\" target=\"_blank\">other resources<\/a> (such as images, videos, style sheets, scripts) are loaded over an insecure HTTP connection. The HTML and PHP pages that includes non-HTTPS resources has to be updated. This may result in failing to load content (eg. images) or your web browser to throw out errors. The client (web browser) will display connection is not secure error.<\/p>\n<figure id=\"attachment_10799\" aria-describedby=\"caption-attachment-10799\" style=\"width: 740px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_mixed_error.jpg\"><img decoding=\"async\" data-attachment-id=\"10799\" data-permalink=\"https:\/\/sanuja.com\/blog\/force-ssl-tls-https-with-htaccess\/tls_mixed_error\" data-orig-file=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_mixed_error.jpg\" data-orig-size=\"740,299\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"tls_mixed_error\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;TLS mixed content error on Firefox and Chrome.&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_mixed_error-300x121.jpg\" data-large-file=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_mixed_error.jpg\" src=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_mixed_error.jpg\" alt=\"TLS mixed content error\" width=\"740\" height=\"299\" class=\"size-full wp-image-10799\" srcset=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_mixed_error.jpg 740w, https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_mixed_error-300x121.jpg 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><figcaption id=\"caption-attachment-10799\" class=\"wp-caption-text\">TLS mixed content error on Firefox and Chrome.<\/figcaption><\/figure>\n<p>A properly configured TLS that serves HTTPS should have the padlock symbol displayed on the corner of most web browsers.<\/p>\n<figure id=\"attachment_10800\" aria-describedby=\"caption-attachment-10800\" style=\"width: 740px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_secure.jpg\"><img decoding=\"async\" data-attachment-id=\"10800\" data-permalink=\"https:\/\/sanuja.com\/blog\/force-ssl-tls-https-with-htaccess\/tls_secure\" data-orig-file=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_secure.jpg\" data-orig-size=\"740,288\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"tls_secure\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;TLS secured connection on Firefox and Chrome.&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_secure-300x117.jpg\" data-large-file=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_secure.jpg\" src=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_secure.jpg\" alt=\"TLS secured connection\" width=\"740\" height=\"288\" class=\"size-full wp-image-10800\" srcset=\"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_secure.jpg 740w, https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_secure-300x117.jpg 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><figcaption id=\"caption-attachment-10800\" class=\"wp-caption-text\">TLS secured connection on Firefox and Chrome.<\/figcaption><\/figure>\n<p>After you update your .htaccess file to force HTTPS, anything that is hosted in your web server should now be able to server files in HTTPS (TLS). For example, if you have CSS style sheets, they should be able to serve the style sheets with <strong>https<\/strong>:\/\/sanuja.com\/style.css instead of <strong>http<\/strong>:\/\/sanuja.com\/style.css. This applies to all other resources such as images, JavaScript, etc. You can use Final and Replace function of most text editors to find \u201chttp:\/\/\u201d and replace that with \u201chttps:\/\/\u201d.<\/p>\n<p>If your website contains external resources, please check if those resources are offered in HTTPS. All Google services such as Google Analytics, Custom Site Search and Google Ads are provided in HTTPS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google has announced that implementation of TLS (SSL) certificates benefit the web site owners and can boost SEO ranking of your website. Secure Sockets Layer (SSL) is the predecessor to Transport Layer Security (TLS). It is a misnomer that people call SSL and TLS are interchangeable. Simply put, as a website owner, what you should &hellip; <a href=\"https:\/\/sanuja.com\/blog\/force-ssl-tls-https-with-htaccess\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Force SSL\/TLS (HTTPS) with .htaccess<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":10799,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,34],"tags":[38,7,19],"class_list":["post-10798","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computer-science","category-cms","tag-featured","tag-server","tag-tutorials"],"jetpack_featured_media_url":"https:\/\/sanuja.com\/blog\/wp-content\/uploads\/2020\/06\/tls_mixed_error.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/posts\/10798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/comments?post=10798"}],"version-history":[{"count":0,"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/posts\/10798\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/media\/10799"}],"wp:attachment":[{"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/media?parent=10798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/categories?post=10798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanuja.com\/blog\/wp-json\/wp\/v2\/tags?post=10798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}