Knowledgebase

How to force custom SSL by using an .htaccess file

  • إعادة توجيه http إلى HTTPS htaccess ووردبرس], htaccess redirect to https with www, force https cpanel, force https hostgator, htaccess force https and non www, force https wordpress, htaccess http to https, redirect http to https htaccess wordpress, htaccess force https and www, قوة htaccess HTTPS و www, هتكس قوة HTTPS وغير شبكة الاتصالات العالمية
  • 0

How to force custom SSL by using an .htaccess file
The use of SSL encrypted web site visitors is very important. In previous articles, we mentioned the importance of encrypted SSL communication. You can refer to the previous articles to learn about the encrypted SSL connection and its importance to your website.

Through this article you can force your visitors to use SSL encrypted:
You can do this by using your htaccess file using mod_rewrite.

The power of all web traffic
You can use this code at the very least to force all visitors to your site to use HTTPS. Just enter the code inside the .htaccess file for your own web site:

Rewrite the Rewrite Engine On

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

with confirmation of replacement  example.com In your domain name. 

Force Specific Domain

To enforce a specific scope for using HTTPS, add that code below the lines within the .htaccess file (root folder) of your website.

RewriteEngine On
RewriteCond% {REQUEST_URI}! ^ / [0-9] \ .. \. cpaneldcv $
RewriteCond% {REQUEST_URI}! ^ / \. Famous / pki-validation / [A-F0-9] {32} \. txt (?: \ Comodo \ DCV)? $
RewriteCond% {HTTP_HOST} ^ example \ .com [NC]
RewrriteCond% {SERVER_PORT} 80
RewriteRule ^ (. *) $ Https://www.example.com/$1 [R, L]

Make sure to replace example \ .com with the name of the domain you are trying to force on https. As well as replacing www.example.com with your existing domain name.

Enforce a specific folder

With the code at the bottom of the line, you can insert ssl into a specific folder inside your site. You can do this by adding the code inside the specified folder within .htaccess.

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

Before you finish, be sure to change the folder reference to the current folder name and ensure that www.example.com/folder is replaced by your actual domain name and the folder you want to force SSL on.





Was this answer helpful?