How Redirect HTTP to HTTPS automatically

Sunday 01th, Apr, 2018 | #Security


If you have a secure certificate (SSL) on your website, you can automatically redirect visitors (HTTP) to the secured (HTTPS) version of your website to make sure their information is protected.

Using .htaccess (Linux - Cpanel)



RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Using web.config (Windows-based)

 
<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>