From HTTP to HTTPS
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 like buttons from Facebook or Twitter, or other social sites, the counters will be reset because the URLs have changed!
Only Google+ follows redirections and transfers the count to the new URL. For the others... - If you use Disqus, all comments will disappear for the same reason.
Disqus offers three migration tools, a domain transfer, a URL mapping and a scanner that recognizes 301 redirects and transfers comments to the new address.
Only the last one is really useful, but if the other two have been created it is probably that it does not work well. In my experience, none of the three actually works. - All your internal links and backlinks become redirects. For backlinks, there is nothing to do (and it does not penalize the site), but for internal links, you will find here a PHP script to convert the URLs.
- Embedded videos disappear. Links on videos must be in https if the page is https!
The script also works for embedded videos with this parameter: www.youtube.com.
Redirections
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 ^(.*)$ https://www.example.com/$1 [R=301,L]
Replace "www.example.com" 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.
- Make a copy of the site in a temporary directory.
- Start the script.
- Verify that the numbers that appear are consistent.
- Look at the source code of the pages to see the result.
- Especially pages that would have a particular format.
If all goes well you can put the content online.
Download:
To use the script:
- Download the archive and unpack it in a directory, for example in c :.
- Go to the directory that contains the image of your site.
- Type:
php c:/http2https/tohttps.php www.example.com
- 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.