How to Redirect HTTP to HTTPS automatically
[gtranslate]
Even though If you have a secure certificate (SSL) on your website, you might be facing problem several times while redirecting automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.
For example
I have my own domain http://www.ashokkuikel.com.np
and I want to redirect it to https://www.ashokkuikel.com.np
Steps
- Login to respective domain cpanel2.Enter correct username and password to enter into Cpanel as belows and Click into the file manager3.Select Public_html folder and Click Setting at the right corner
4. Check Show Hidden files and Select OK Button.
5.Right Click on .htaccess file then click code edit and again click edit Button.
6.Insert the Following Code before closing tag </Ifmodule>
Linux & cPanel
Linux-based accounts use
.htaccess
files to handle redirection. If you need to create a .htaccess
file, you can use your control panel's file manager (Web & Classic / cPanel).
Using the following code in your
.htaccess
file automatically redirects visitors to the HTTPS version of your site: RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Windows & Plesk
Windows-based accounts useweb.config
files to handle redirection.
Using the following code in yourweb.config
file automatically redirects visitors to the HTTPS version of your site
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If you have an existing
web.config
file:- Ensure you have sections (i.e. opening and closing tags) for:
System.webServer
(which containsrewrite
)rewrite
(which containsrules
)rules
(which contains one or morerule
sections)
Insert any of those sections that do not exist. - Insert the entire
rule
section, includingmatch
,conditions
, andaction
, inside therules
section
7.Finally save the file and enter the domain and experience the magic
How to Redirect HTTP to HTTPS automatically
Reviewed by Ashok
on
Thursday, May 25, 2017
Rating:
No comments