Monday , February 3 2025

Correct transfer Drupal site from http to https

The certificate was purchased and activated, the site with https does not open correctly. The way to solve this problem:

1. In the file sites/default/settings.php find the line with $base_url. Under this line add:

$conf['https'] = TRUE;
$base_url = 'https://old.domain.com';

Replace the domain name with the actual one, and do not put a slash after the domain!

2. In the source code of the page, you can see that there are many mentions of http:// in the content and in the head section.

Edit files:

/sites/all/themes/yourtheme/template.php
/sites/all/themes/yourtheme/templates/html.tpl.php
/robots.txt
/sitemap.xml (if exists on the server in the list of files)

and in these files replace all http:// to the https://.

3. Edit .htaccess, after RewriteEngine on add this one:

RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://%1/$1 [L,R=301] 
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

A redirect from www to a case with https is not needed, but I need it for copying as part of this task.

Next, go to edits in the database. In the source code, see what links are left with HTTP and look for links in PhpMyAdmin or Adminer and make SQL queries in the format:

UPDATE field_data_body SET body_value = REPLACE(body_value, 'http://', 'https://');

After editing the database, go to the admin panel /admin/config/development/performance (Configuration > Development > Performance) and then clear the cache.

When all links are updated in the files and in the database, a notification “Connection is secure” will appear on the site.

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

Popup image on click without href

A very elegant solution, with which the image will not be wrapped in <a href=””></a>, …

Leave a Reply

Your email address will not be published. Required fields are marked *