Redirect to HTTPS with 301 (Permanently)

For Linux / cPanel

use the following code in .htaccess. If you have an existing .htaccess file: Do not duplicate RewriteEngine On. Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.

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

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$$1  [L,R=301]

For Windows / Plesk

These accounts use web.config files to handle redirection.
Using the following code in your web.config file automatically redirects visitors to the HTTPS version of your site:

	<rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
	<match url="(.*)" /> 
		<add input="{HTTPS}" pattern="off" ignoreCase="true" />
	<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />

If you have an existing web.config file: Ensure you have sections (i.e. opening and closing tags) for: system.webServer (which contains rewrite) rewrite (which contains rules) rules (which contains one or more rule sections)Insert any of those sections that do not exist. Insert the entire rule section, including match, conditions, and action, inside the rules section.

Leave a Reply

Your email address will not be published. Required fields are marked *