Redirect To HTTPS (SSL) In WordPress
Before you run redirection code, you need to have Secure Sockets Layer (SSL) or Secure Certificate on your website. You need to keep in mind that just installing SSL certificate on your website doesn’t let your visitors automatically redirected to secured (HTTPS) version of your website. You need to write some codes in your functions.php or .htaccess file to make sure your communications are properly encrypted. When it comes to reliability, anti-spams or security, HTTPs comes to handy. You can REDIRECT to https (SSL) in WordPress by just using a simple snippet in your config.php
file or .htaccess
file.
What are HTTP and HTTPS?
Hyper Text Transfer Protocol Secure or simply HTTPS, is the secure version of HTTP. HTTP is the protocol over which data/package is sent between the browser and the website which you are connected to. The letter ‘S’ at the end of HTTPS stands for ‘Secure’ which means all the transmissions and communications between your website and the browsers are encrypted thoroughly. HTTPS is used to secure/protect highly confidential online transactions like personal information, transactions, and
Moreover, HTTPS is used to secure/protect highly confidential online transactions like personal information, transactions, and many more. In short, HTTPS protocol is always better than HTTP.
Why Use SSL?
The main reason behind using SSL is to keep the information sent across the internet secure and encrypted so only the receiver can get the required message. As the increment of hackers on the daily basis is immense, it is always important that the information you send through the internet is reached to the destination server without any hurdle. Therefore, the usernames and passwords should also be encrypted in a very tight way. And SSL is a reliable tool for this.
When SSL certificate is used, it will automatically make the data unreadable to anyone except to the server your information is being sent. Even Identity thieves and hackers get no chance to access it.
Where Can I Get SSL Certificate?
There are various Large IT Industries that provides SSL certificate. ( not for free of course )
Five popular preferences are:
1. GoDaddy
2. Verisign
3. Comodo
4. Digicert
5. Thawte
However, your options are not limited only to above Five preferences. You may find other option entirely to be way better and cost effective. For me (What I Think ) the cheapest and reliable provider is SSL Shopper. But you can choose which is effective for you.
Redirect To HTTPS (SSL) In WordPress
OK, now let’s go to the coding part. We can redirect the site to secure HTTPs using both functions.php
or .htaccess
file in WordPress. You can run the following code either in .htaccess
or functions.php
file. Copy the code below:-
PHP Function to Redirect http to “HTTPs”
function redirectToHTTPS(){ if($_SERVER['HTTPS']!="on"){ $redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; header("Location:$redirect"); }} add_action('init','redirectToHTTPS' );
Redirect website to “https” using .HTACCESS
RewriteEngine On RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Now, users are redirected to secure HTTPS site when they enter your site.
If you have any query, please leave your message in the form below.