{"id":4160,"date":"2024-06-16T21:05:43","date_gmt":"2024-06-16T15:35:43","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=4160"},"modified":"2025-03-07T10:04:37","modified_gmt":"2025-03-07T04:34:37","slug":"how-to-redirect-http-to-https-using-htaccess","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-redirect-http-to-https-using-htaccess\/","title":{"rendered":"How to Redirect HTTP to HTTPS using .htaccess?"},"content":{"rendered":"\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Secure-Your-Website-with-HTTPS-1.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"416\" data-id=\"4184\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Secure-Your-Website-with-HTTPS-1.jpg\" alt=\"How to Redirect HTTP to HTTPS using .htaccess?\" class=\"wp-image-4184\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Secure-Your-Website-with-HTTPS-1.jpg 1200w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Secure-Your-Website-with-HTTPS-1-300x104.jpg 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Secure-Your-Website-with-HTTPS-1-1024x355.jpg 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Secure-Your-Website-with-HTTPS-1-768x266.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>In this guide, we will walk you through the process of redirecting HTTP to HTTPS using the .htaccess file, the powerful configuration file for Apache servers. To successfully redirect HTTP to HTTPS using <a href=\"https:\/\/www.veeble.org\/kb\/what-is-htaccess-in-wordpress\/\" target=\"_blank\" rel=\"noopener\">.htaccess<\/a>, ensure your server has an <a href=\"https:\/\/www.veeble.org\/in\/ssl\/\" target=\"_blank\" rel=\"noopener\">SSL certificate<\/a> installed. Without an SSL certificate, browsers will display a security warning to users, which can deter them from visiting your site.<\/p>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-3e949761      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#how-to-force-all-urls-to-use-https\" class=\"uagb-toc-link__trigger\">How to Force All URLs to Use HTTPS?<\/a><li class=\"uagb-toc__list\"><a href=\"#how-to-force-only-a-specific-url-to-use-https\" class=\"uagb-toc-link__trigger\">How to Force Only a Specific URL to Use HTTPS?<\/a><li class=\"uagb-toc__list\"><a href=\"#how-to-force-https-on-a-specific-folder\" class=\"uagb-toc-link__trigger\">How to Force HTTPS on a Specific Folder?<\/a><li class=\"uagb-toc__list\"><a href=\"#how-to-force-https-on-a-subdomain\" class=\"uagb-toc-link__trigger\">How to Force HTTPS on a Subdomain?<\/a><li class=\"uagb-toc__list\"><a href=\"#skyrocket-your-websites-performance-with-veebles-fully-managed-vps\" class=\"uagb-toc-link__trigger\">Skyrocket Your Website&#039;s Performance with Veeble&#039;s Fully Managed VPS<\/a><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<p><\/p>\n\n\n\n<p>Navigate to the <a href=\"https:\/\/www.tecmint.com\/find-apache-documentroot-in-linux\/\" target=\"_blank\" rel=\"noopener\">document root of your domain<\/a> and create a <code>.htaccess<\/code> file. In this file, add the redirection code based on your specific requirements, referring to the relevant sections from the Table of Contents above.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-force-all-urls-to-use-https\">How to Force All URLs to Use HTTPS?<\/h3>\n\n\n<p>To force redirect HTTP to HTTPS on all traffic using <code>.htaccess<\/code>, you need to add the following rules to your <code>.htaccess<\/code> file. This file is usually located in the root directory of your website. Open the <code>.htaccess<\/code> file in a text editor and add the following code to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On<br>RewriteCond %{HTTPS} off<br>RewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;L,R=301]<\/code><\/pre>\n\n\n\n<div class=\"wp-block-group is-horizontal is-content-justification-left is-nowrap is-layout-flex wp-container-core-group-is-layout-8ad9adab wp-block-group-is-layout-flex\">\n<p>This code does the following:<\/p>\n\n\n\n<p><code>RewriteEngine On<\/code>: Enables the runtime rewriting engine.<br><code>RewriteCond %{HTTPS} off<\/code>: Checks if the HTTPS is off (i.e., the request is not secure).<br><code>RewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [L,R=301]<\/code>: Redirects all HTTP requests to HTTPS. The <code>R=301<\/code> flag specifies a permanent redirection.<\/p>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-force-only-a-specific-url-to-use-https\">How to Force Only a Specific URL to Use HTTPS?<\/h3>\n\n\n<p>To force redirect HTTP to HTTPS only a specific URL using <code>.htaccess<\/code>, you can use the following code snippet. This snippet will redirect only the specified URL from HTTP to HTTPS. Open the <code>.htaccess<\/code> file in a text editor and add the following code to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteCond %{REQUEST_URI} ^\/your-specific-url$\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;L,R=301]<\/code><\/pre>\n\n\n\n<p>Replace <code>\/your-specific-url$<\/code> with the path of the specific URL you want to force to HTTPS. For example, if you want to force <code>http:\/\/www.yourwebsite.com\/specific-page<\/code> to use HTTPS, you would replace <code>\/your-specific-url$<\/code> with <code>\/specific-page$<\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-force-https-on-a-specific-folder\">How to Force HTTPS on a Specific Folder?<\/h3>\n\n\n<p>To force redirect HTTP to HTTPS on all traffic within a specific folder using <code>.htaccess<\/code>, you can use a similar approach to the one used for a specific URL, but instead, you target a directory. Open the <code>.htaccess<\/code> file in a text editor and add the following code to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteCond %{REQUEST_URI} ^\/your-folder\/\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;L,R=301]<\/code><\/pre>\n\n\n\n<p>Replace <code>\/your-folder\/<\/code> with the path to the folder you want to secure with HTTPS. Here make sure the .htaccess file is created and placed in the same folder you wish to set redirection rule.<\/p>\n\n\n\n<p><\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-force-https-on-a-subdomain\">How to Force HTTPS on a Subdomain?<\/h3>\n\n\n<p>To force HTTPS on a specific subdomain, such as <code>subdomain.yourwebsite.com<\/code>, you can use the following code in your <code>.htaccess<\/code> file. For that open the .htaccess file with a text editor and add the lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On<br>RewriteCond %{HTTPS} off<br>RewriteCond %{HTTP_HOST} ^subdomain.yourwebsite.com$<br>RewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;L,R=301]<\/code><\/pre>\n\n\n\n<p>For example, if your subdomain is <code>blog<\/code> and your domain is <code>example.com<\/code>, you would update the lines as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On<br>RewriteCond %{HTTPS} off<br>RewriteCond %{HTTP_HOST} ^blog.example.com$<br>RewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;L,R=301]<\/code><\/pre>\n\n\n\n<div class=\"wp-block-uagb-separator uagb-block-bd5c9668\"><div class=\"wp-block-uagb-separator__inner\" style=\"--my-background-image:\"><\/div><\/div>\n\n\n\n<p>By following this guide, you&#8217;ll successfully redirect HTTP to HTTPS using .htaccess, ensuring a secure and trustworthy experience for your users.<\/p>\n\n\n\n<p>It&#8217;s crucial to test the redirection after configuring the .htaccess file to verify that it functions correctly. Additionally, regularly reviewing and updating the .htaccess file is recommended to adapt to any changes in your website structure or redirection requirements.<\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-11086cbe wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Skyrocket Your Website&#8217;s Performance with Veeble&#8217;s Fully Managed VPS<\/h3><p class=\"uagb-cta__desc\">Don&#8217;t settle for less. Choose Veeble&#8217;s fully managed VPS hosting and get the performance, security, and support you need to take your business to the next level.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/managed-vps\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Explore Plans<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Also Read:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-veeble-hosting wp-block-embed-veeble-hosting\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.veeble.org\/kb\/what-is-htaccess-in-wordpress\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to redirect HTTP to HTTPS using .htaccess for all URLs, specific URLs, folders, and subdomains to boost security of your website.<\/p>\n","protected":false},"author":7,"featured_media":7852,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","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":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","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-opacity":"","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-opacity":"","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-opacity":"","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-opacity":"","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-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2,15],"tags":[],"class_list":["post-4160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache","category-developers-stuff"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/How-to-Redirect-HTTP-to-HTTPS-using-.htaccess.jpg",1366,768,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/How-to-Redirect-HTTP-to-HTTPS-using-.htaccess-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/How-to-Redirect-HTTP-to-HTTPS-using-.htaccess-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/How-to-Redirect-HTTP-to-HTTPS-using-.htaccess-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/How-to-Redirect-HTTP-to-HTTPS-using-.htaccess-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/How-to-Redirect-HTTP-to-HTTPS-using-.htaccess.jpg",1366,768,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/How-to-Redirect-HTTP-to-HTTPS-using-.htaccess.jpg",1366,768,false]},"uagb_author_info":{"display_name":"Adrian Antony","author_link":"https:\/\/www.veeble.com\/kb\/author\/adrian\/"},"uagb_comment_info":0,"uagb_excerpt":"Learn how to redirect HTTP to HTTPS using .htaccess for all URLs, specific URLs, folders, and subdomains to boost security of your website.","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/4160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=4160"}],"version-history":[{"count":26,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/4160\/revisions"}],"predecessor-version":[{"id":7765,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/4160\/revisions\/7765"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/7852"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=4160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=4160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=4160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}