Redirecting a Web Server’s IP Address to the HTTPS Version of Its Associated Website: 1 Example Using Drupal and 1 Using Publii

In this article, we'll discuss why it's important to redirect all version of your website to the secure version of your website: the one that has a Secure Sockets Layer (SSL) certificate. and that begins with https://.

Assumptions: we have two websites: one is a Drupal website, and the other is a Publii website. Both are hosted on Linodes running the lastest LTS (Long-Term Support) version of Ubuntu. We want all versions of the websites, including the raw ip addresses of the websites, to redirect to the https:// version of each website. Our webserver sofdtware is the latest version of Apache.

What is an SSL Certificate, why is it important, and what is it used for?

An SSL certificate encrypts data exchanged between a website and its users. This keeps sensitive information like passwords and payment details safe from hackers. It also verifies the website's identity, ensuring users are on a legitimate and secure site. The padlock icon and "https" in the URL show this added security. SSL certificates help build trust, especially for websites handling private information or online transactions. They can also improve a website's credibility and search engine ranking by signaling a secure connection.

What is Cerbot, and why do so many websites use it to generate their SSL certificates?

Certbot is a free, open-source tool that automates the process of obtaining and renewing SSL certificates from Let's Encrypt, a widely used certificate authority. Certbot simplifies the installation and management of SSL certificates, allowing websites to enable secure HTTPS connections without manual configuration. Many websites use Certbot because it is easy to set up, free to use, and it automates certificate renewals, ensuring websites remain secure without needing frequent intervention from administrators.

What is Drupal, and why is it so popular for creating websites?

Drupal is a free, open-source content management system (CMS) used to build and manage websites. It is popular because it offers a high level of flexibility, allowing developers to create complex and customized websites with advanced features. Drupal is known for its strong security, scalability, and robust community support. Its modular architecture lets users extend functionality through thousands of add-ons, making it ideal for large organizations, government websites, and businesses needing highly tailored solutions.

What is Publii, and why is it so popular for creating websites?

Publii is a free, open-source static site generator designed for creating and managing fast, secure, and privacy-friendly websites without needing a database or server-side processing. It’s popular because it’s user-friendly, allowing non-technical users to build websites with a drag-and-drop interface while offering powerful features like SEO optimization, customization options, and one-click publishing. Publii generates static HTML files, which makes websites faster, more secure, and easier to host, especially on platforms like GitHub Pages or Netlify. It’s favored by bloggers, small businesses, and users prioritizing speed, simplicity, and security.

What is Linode, and why is it so popular for hosting websites?

Linode is a cloud hosting provider that offers virtual private servers (VPS) and other cloud services. It's popular because it combines flexibility with straightforward pricing, making it easy for developers and businesses to set up and scale their projects. Linode is known for its performance, solid uptime, and strong support, which helps users solve issues quickly. Its flexibility allows users to adjust server resources as their needs grow, making it a preferred choice for hosting websites, apps, and other cloud-based projects.
Problem #1:
We have a Drupal website: https://example.com. The ip address of the hosting Linode vps is 123.123.123.123. When you enter the ip addresss into the address bar. You are taken to http://example.com. How do we fix this so you are instead redirected to https://example.com.
  •  
    To solve the issue where entering the raw IP address redirects users to http://example.com instead of https://example.com, you can configure Apache to force redirection from the IP address to the HTTPS version of the domain. Here's how you can achieve this:
    Steps to Redirect IP to HTTPS Version
    1. To solve the issue where entering the raw IP address redirects users to http://example.com instead of https://example.com, you can configure Apache to force redirection from the IP address to the HTTPS version of the domain. Here's how you can achieve this:
    2. Steps to Redirect IP to HTTPS Version

      1. Access Your Server via SSH: Connect to your Linode VPS using SSH.
      2. Open the Apache Configuration: You need to edit the Apache configuration file. Typically, this file is found in /etc/apache2/sites-available/000-default.conf or another file you've configured for your virtual host.
      3. Run: sudo nano /etc/apache2/sites-available/000-default.conf
      4. Configure Redirection for IP Address: Add the following configuration to redirect traffic from the IP address to https://example.com:
      5. <VirtualHost *:80>
        ServerName 123.123.123.123
        Redirect 301 / https://example.com/
        </VirtualHost>
      6. Enable Apache Rewrite Module: If it’s not already enabled, you need to enable the Apache rewrite module to handle redirections:
        • sudo a2enmod rewrite
      7. Reload Apache: After saving the configuration file, reload Apache to apply the changes:
      8. sudo systemctl reload apache2
      9. Now, when a user tries to access your server using the raw IP address (e.g., http://123.123.123.123), they will be redirected to https://example.com, ensuring that all traffic is encrypted and routed through the secure version of your website.

        Problem #2:

        We have a Publii website: https://myblog.com. The IP address of the hosting Linode VPS is 111.111.111.111. Currently, accessing the IP address in a browser takes you to http://myblog.com. How can we fix this to redirect users to https://myblog.com?

        For the Publii website hosted on a Linode VPS using Apache, we follow a similar approach to ensure that accessing the raw IP address redirects users to the HTTPS version of the website.

        Steps to Redirect IP to HTTPS Version for Publii

        1. Access Your Server via SSH:
        Connect to your Linode VPS using SSH:

        ssh username@111.111.111.111
      2. Edit the Apache Configuration File:
      Open the Apache configuration file for the Publii site. This file is usually found in /etc/apache2/sites-available/, named something like myblog.conf:

    3. sudo nano /etc/apache2/sites-available/myblog.conf
    4. Configure Redirection for IP Address:
      Add a VirtualHost block to redirect requests from the IP address to https://myblog.com:
    5. <VirtualHost *:80>
          ServerName 111.111.111.111
          Redirect 301 / https://myblog.com/
      </VirtualHost>
    6. Enable Apache Rewrite Module (if needed):
      To handle redirections, make sure the rewrite module is enabled:
    7. sudo a2enmod rewrite
    8. Reload Apache to Apply Changes:
      Save your changes to the configuration file, then reload Apache to apply the new settings:
    9. sudo systemctl reload apache2
    10. With this setup, any requests made to http://111.111.111.111 will automatically redirect to https://myblog.com, ensuring a consistent and secure browsing experience for your users.

Summary

Redirecting the raw IP address to the HTTPS version of a website is crucial for maintaining secure connections, consistent branding, and user trust. By configuring Apache correctly, both the Drupal and Publii websites can automatically redirect all traffic, including from their IP addresses, to their secure HTTPS versions, ensuring all users experience the highest level of security and confidence in your site.

You should also read: