How to transfer a WordPress site on https

Free SSL Certificate

At present each user takes care of his site security and the data that is stored on it. SSl certificates are used for this and secure the protection of your site. Avahost.net company provides free certificates from COMODO. Let’s look at how to transfer a WordPress site on https.

Initially, you need to protect your password when logging in to the admin panel. To do this open the wp-config.php file and write the line: define(‘FORCE_SSL_ADMIN’, true);. After that, change the site address to Https in the settings. To do this go to the “Settings” – “general” and specify your website address, for example, https://www.avahost.net. Then we replace the internal links of the site with https. It is necessary to use relative addresses instead of absolute ones. Https://www.avahost.net/hosting/main/ is an absolute; / main / is a relative. After that, make a SQL query in the database. For the site https://www.avahost.net it’s next:

UPDATE wp_posts SET post_content = REPLACE (post_content, ‘http://avahost.net’, ‘https://Avahost.net’);

You can make all links relative at once:

UPDATE wp_posts SET post_content = REPLACE (post_content, ‘http://avahost.net/’, ‘/’);

You need to go to Cpanel and select PhPMyAdmin in order to make such requests.
After that select the required database; go to the SQL tab and enter the required query.
When everything is done it is advisable to check your site for the remaining http links. Find them and also replace them.
You can do this with free services for checking site links.

After all this, you need to tell the search engines that your site works through Https using the 301 redirect.
This is necessary to make sure that all visitors automatically redirect to the new site address and without losing the search traffic.
You can do this by writing code in the htaccess:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Or you can do it via PHP code. In this way you need to write the code in the functions.php template:

function force_https () {
if ( !is_ssl() ) {
wp_redirect(‘https://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’], 301 );
exit();
}
}
add_action ( ‘template_redirect’, ‘force_https’, 1 );

When you do all this your site will be guaranteed to be protected.