Converting HTTP Links to HTTPS

Tips and script for converting a website to secure SSL.

A script is provided to automatically convert internal HTTP links to HTTPS on the local site image. If your site uses a CMS, it will not work, but a CMS with a problem provides tools or plugins for conversion.

Before you turn your http site into https, you need to know some things...

Redirections

If you have mutual hosting, your hosting can offer you a paid or free SSL certificate using Let's Encrypt.
After you are assigned this certificate, your site has a duplicate, each page has an http-URL and https-URL.
This creates a duplicate glad that it is better to avoid, and for this you need to redirect http pages to https pages .

To do this, you will add redirection code in the .htaccess file to the site root if the server is Apache.

Standard code:

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

This code is offered by GoDaddy and should be universal. If you are not sure that you will finally switch to https, replace the 301 code with 302.

If you have OVH hosting, it offers you the following code:

OBX code:

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

Replace "www.example.com" with the site name.

For another hoster, or if the server is not Apache, you should read their documentation.

Director's script

The script is written in PHP and requires PHP 7 to be pre-installed. This is a simple program that replaces lines in each file.

Before running the script on the site content, you must take several precautions. Even if the code worked great on the sites where I used it, not all sites are designed the same way.

If everything is in order, you can put the content on the Internet.

Download:

To use a script:

  1. Load the archive and unpack it into a directory, for example, in c:.
  2. Navigate to the directory containing the site image.
  3. Enter:
    php c:/http2https/tohttps.php www.example.com
  4. Then put the content on the Internet.

See also...

Advertise. This script is optional, it replaces redirected links with new URLs, but for all domains. However, it is much slower.