Advices and a script to convert a web site to the secure SSL protocol.

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

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


If you have a shared hosting, your host can offer you a paid SSL certificate or free with Let's Encrypt.
Once this certificate is assigned to you, your site exists in duplicate, each page has an http URL and an https URL.
This creates a duplicate content that is best avoided, and for this you need to redirect the http pages to the https pages.

To do this, you will add a redirect code in the .htaccess file at the root of the site, if the server is Apache.

Standard code:

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

This code is proposed by GoDaddy and must be universal. If you are not sure if you want to permanently switch to https, replace code 301 with 302.

If you have an OVH hosting, it proposes the following code:

OVH code:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R=301,L]

Replace "" with the name of your site.

For another host, or if the server is not Apache, you should consult their documentation.

The script

The script is written in PHP and requires the installation of PHP 7. It is a simple program that performs a string replacement in each file.

Before starting the script on the content of your site, some precautions are to be taken. Even though the code worked perfectly on the sites where I used it, not all sites are designed in the same way.

If all goes well you can put the content online.


To use the script:

  1. Download the archive and unpack it in a directory, for example in c :.
  2. Go to the directory that contains the image of your site.
  3. Type:
    php c:/http2https/tohttps.php
  4. Then put the content online.

See also ...

Unredir. This script is complementary, it replaces links redirected by new URLs, but for all domains. However it is much slower.