{"id":31505,"date":"2021-02-09T22:21:55","date_gmt":"2021-02-09T14:21:55","guid":{"rendered":"https:\/\/web.mwwsb.com.my\/pjci\/?post_type=kb&#038;p=31505"},"modified":"2022-09-07T21:47:36","modified_gmt":"2022-09-07T13:47:36","slug":"redirect-all-traffic-to-https-using-an-htaccess-file","status":"publish","type":"kb","link":"https:\/\/www.casbay.com\/guide\/kb\/redirect-all-traffic-to-https-using-an-htaccess-file","title":{"rendered":"Redirect all traffic to HTTPS using an .htaccess file."},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"31505\" class=\"elementor elementor-31505\" data-elementor-post-type=\"kb\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-e894ffc elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e894ffc\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-40a981e\" data-id=\"40a981e\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-60d729e elementor-widget elementor-widget-heading\" data-id=\"60d729e\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Redirect all traffic to HTTPS using an .htaccess file<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d4e6f32 elementor-widget elementor-widget-heading\" data-id=\"d4e6f32\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">What is SSL?<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-eefd193 elementor-widget elementor-widget-image\" data-id=\"eefd193\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/casbay.com\/guide\/wp-content\/uploads\/2021\/02\/SSL-Secure-Connection.png\" title=\"\" alt=\"\" loading=\"lazy\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3083702 elementor-widget elementor-widget-text-editor\" data-id=\"3083702\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Secure Sockets Layer or SSL is a standard security protocol to establish encrypted links and communication between a web server and a browser.<\/p><p>SSL is commonly used to ensure that all data transmitted between the web server and browser remains encrypted.<\/p><p>An\u00a0<strong>SSL certificate<\/strong> is necessary to create SSL connection. You would need to give all details about the identity of your website and your company as and when you choose to activate SSL on your web server.<\/p><p>In order to force your web traffic to use HTTPS, you need to edit the codes in the <strong>.htaccess file.<\/strong><\/p><p>Before we move onto redirecting HTTP to HTTPS, click <a href=\"https:\/\/www.casbay.com\/guide\/kb\/how-to-edit-htaccess-file-via-the-cpanel-filemanager-2\/\">HERE<\/a> to find out how you can edit .htaccess file. If you already know, you can proceed with this guide.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-18e2d76 elementor-widget elementor-widget-heading\" data-id=\"18e2d76\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">1. Redirect All Web Traffic<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-778ccb2 elementor-widget elementor-widget-text-editor\" data-id=\"778ccb2\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>If you have existing code in your .htaccess, add the following:<\/p><pre><code>RewriteEngine On\nRewriteCond %{SERVER_PORT} 80\nRewriteRule ^(.*)$ https:\/\/www.example.com\/$1 [R,L]<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-73e94ac elementor-widget elementor-widget-heading\" data-id=\"73e94ac\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">2. Redirect Only a Specific Domain<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3ddfb2f elementor-widget elementor-widget-text-editor\" data-id=\"3ddfb2f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>To redirect a specific domain to use HTTPS, add the following:<\/p><pre><code>RewriteEngine On\nRewriteCond %{HTTP_HOST} ^yourdomain\\.com [NC]\nRewriteCond %{SERVER_PORT} 80\nRewriteRule ^(.*)$ https:\/\/www.example.com\/$1 [R,L]<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8e3ed32 elementor-widget elementor-widget-heading\" data-id=\"8e3ed32\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">3. Redirect Only a Specific Folder<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-57c2784 elementor-widget elementor-widget-text-editor\" data-id=\"57c2784\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>To redirect HTTPS on a specific folder, add the following:<\/p><pre><code>RewriteEngine On\nRewriteCond %{SERVER_PORT} 80\nRewriteCond %{REQUEST_URI} folder\nRewriteRule ^(.*)$ https:\/\/www.example.com\/folder\/$1 [R,L]<\/code><\/pre><p><strong>Note<\/strong>: Replace\u00a0<em><code>\u201cexample\u201d<\/code><\/em>\u00a0with your actual domain name wherever required. Also, in case of the folder, replace<em>\u00a0<code>\/folder<\/code><\/em>\u00a0with the actual folder name.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5ebc3a8 elementor-widget elementor-widget-text-editor\" data-id=\"5ebc3a8\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>We hope this article helped you to learn How to redirect traffic to HTTPS using .htaccess file. For more articles, please go to <a href=\"https:\/\/www.casbay.com.my\/guide\/\">Knowledge Base<\/a>.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Redirect all traffic to HTTPS using an .htaccess file What is SSL? Secure Sockets Layer or SSL is a standard security protocol to establish encrypted links and communication between a web server and a browser. SSL is commonly used to ensure that all data transmitted between the web server and browser remains encrypted. An\u00a0SSL certificate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"no-sidebar","site-content-layout":"page-builder","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}}},"kbtopic":[116],"kbtag":[106],"mkb_version":[],"_links":{"self":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/31505"}],"collection":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/comments?post=31505"}],"version-history":[{"count":8,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/31505\/revisions"}],"predecessor-version":[{"id":32062,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/31505\/revisions\/32062"}],"wp:attachment":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/media?parent=31505"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=31505"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kbtag?post=31505"},{"taxonomy":"mkb_version","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/mkb_version?post=31505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}