Thursday, 30 May 2019

Redirect http to https using .htaccess

Redirect your http page to https page using .htaccess file
create .htaccess file in your root folder and paste given code. Change red text to your domain name

<---- start code here ---->

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sakhihosting\.in [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.sakhihosting.in/$1 [R=301,L]


<---- end code here ---->

Redirect Specified Folder

If you want to force SSL on a specific folder, insert the code below into a .htaccess file placed in that specific folder:
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://www.example.com/folder/$1 [R=301,L]


Make sure you change the folder reference to the actual folder name. Then be sure to replace www.example.com/folderwith your actual domain name and folder you want to force the SSL on.

No comments:

Post a Comment