How to Force SSL in a Subfolder (Website)


How to Force SSL in a Subfolder

This is a simple tutorial I am making for anyone wondering how to force SSL inside a subfolder, sometimes the web traffic may not get encrypted when you visit your site’s subfolder even though you already have SSL installed and working on your main site. There might be many reasons why your website is not being redirected to SSL if you have no clue about editing .htaccess files then please do not proceed and you may end up messing your site in redirect loops. Though this should completely be safe.

How to enable SSL on your Subfolder

1) Go to your file manager and navigate to your root folder then to the subfolder where your site is

2) Now if you already have a .htaccess file in it then no need to create another one, just edit the one that is already there, if not then just create a new file and name it “.htaccess” make sure it placed inside the root folder of your subfolder

3) Place this code inside your .htacess file

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://example.com/folder/$1 [R=301,L]

Make sure to replace the “folder” in both the second last line and the last, with the name of your folder and “example.com” with your domain name. If you already have a .htaccess files then place this code under “RewriteEngine On” and if you do not have anything like “RewriteEngine On” in it, then just place it there and place the code under it so it will look something like as seen below

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://example.com/folder/$1 [R=301,L]

4) Click save and you are done, the subfolder should now always redirect to HTTPS

If this method still doesn’t work for you then if you are using Cloudflare already, go to Cloudflare’s SSL setting and enable full strict mode and your subfolder should now be redirected to HTTPS, only do this if the above does not work, don’t do both at the same time.

If you found this tutorial helpful then please share it wherever you can.


A programmer, gamer, and love researching new technology and games, reverse engineering applications. In my spare time, I usually play basketball or watch movies.