CODE CODIFY.CLUB

Redirect HTTP to HTTPS

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

Linux & cPanel

Linux-based accounts use .htaccess files to handle redirection.
Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

# Standard Rule

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

 

# If not using www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.(.*)$ [NC]
RewriteCond %{HTTP:HTTPS} !on
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]

 

# If using www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteCond %{HTTP:HTTPS} !on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


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.

 

Windows & Plesk

Windows-based 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:
<configuration> 
<system.webServer> 
<rewrite>
 <rules>
            <rule name=”HTTP to HTTPS redirect” stopProcessing=”true”> 
            <match url=”(.*)”></match> 
            <conditions>
                   <add input=”{HTTPS}” pattern=”off” ignoreCase=”true”></add> 
             </conditions>
             <action type=”Redirect” redirectType=”Permanent” url=”https://{HTTP_HOST}/{R:1}”></action> 
            </rule>
            </rules>
 </rewrite>
 </system.webServer> 
</configuration>

 

For WordPress

1. Go to the admin dashboard.
2. Point you mouse over Settings and click General.
3. Where it says WordPress Address (URL) and Site Address (URL) replace the http:// part with https:// for both of them.
4. Click Save Changes

V!ral

Developer, Technology aficionado, Beer Lover and founder of codify.club Network. Who shares a keen interest about website development, health issues, cancer awareness and other fun stuff.

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Most popular

Most discussed