How to Force HTTP or HTTPS using .htaccess and WP-Config

How to Force HTTP or HTTPS using .htaccess and WP-Config #

When installing an SSL certificate your website is now available in HTTP and HTTPS (Secure). It is usually best to redirect all HTTP links to HTTPS as these are encrypted and secures your website’s data.

Force HTTPS on All Traffic #

To force HTTPS on all traffic you'll need to create or edit the .htaccess file. This is located in your file manager inside the public HTML folder. If you cant see the file head to the top, right of the screen and press the settings box then click show hidden files (dotfiles).

  1. Open your File Manager in your hosting panel and open .htaccess inside the public_html folder. *If you've enabled hidden files and you still can't see it go to the top, left corner and click +File and name it .htaccess.
  2. Find RewriteEngine On and type/paste the following lines of code below it:
  3. RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  4. Save the changes.

 *Make sure that the line RewriteEngine On is not repeated twice.

 

Force HTTPS on a Certain Domain #

If you have two domain names that go to the same website but you're wanting only one of the domain names to redirect to HTTPS. follow the steps and change conorbradley.co.uk to your domain name:

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

. *Make sure that the line RewriteEngine On is not repeated twice.

Force HTTPS on a Specific Folder #

You can also edit the .htaccess file to force HTTPS on specific folders. The folder you're enabling must be placed in a location that enables HTTPS connection.

  1. RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(images|videos|pages) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Make sure to change the images|videos|pages references to the directory names you have in your file manager as this is an example.

Please clear your browser's cache after making the updates you can do this by following our guide.

 

Forcing HTTP on a WordPress Site #

When creating a new website, sometimes on a subdomain can get stuck using HTTPS as their domain is forced to use SSL. Your new WordPress site needs to sync to their SSL certificate which can take up to 24 hours. If you're wanting to edit your site straight away follow these steps:

  1. Open your hosting file manager > public_html > then find wp-config.php
  2. Just before the "/* That's all, stop editing! Happy publishing. */" paste the following
  3. define('WP_HOME','http://domain.conorbradley.co.uk');
    define('WP_SITEURL','http://domain.conorbradley.co.uk');
  4. make sure you change http://domain.conorbradley.co.uk to your domain name.

*You can also change the HTTP to HTTP when your SSL certificate starts working. This can be checked through AutoSSL in C-Panel if your hosting provider supports this.

 

[smartslider3 slider="2"]

                                             Facebook | Twitter | Instagram | Youtube | Vimeo | Blog | Knowledge Base